Back to all templates

Read CSV and send to DB

Validate rows from a CSV file and load them into a PostgreSQL database.

Description:

Reads a local cities.csv file, parses it, and loops over each row. Rows with both a City and a State value are logged and inserted into the PostgreSQL CITY table; rows missing either value are logged as warnings. After the loop, it queries the row count of the CITY table and logs the total.

Key Features:
  • Local file reading from the ByteChef host
  • CSV parsing with a header row
  • Per-row validation via a condition
  • PostgreSQL inserts for valid rows
  • Warning logs for incomplete rows
  • Post-load row-count query
Prerequisites:
  • Local filesystem access to cities.csv on the ByteChef host
  • A PostgreSQL connection with a CITY table (columns name, country)
Ideal For:

Data engineers loading and validating CSV records into a relational database.

STEPS
  1. Load the cities.csv file from the local machine.
  2. Parse the CSV into rows.
  3. Loop over each row: if both City and State are present, log and insert the row into the PostgreSQL CITY table; otherwise log a warning.
  4. Query the total record count of the CITY table.
  5. Log the total count.
COMPONENTS
Filesystem
Csv File
Logger
CATEGORYDocument Ops

How ByteChef works?

Focus on what matters,
automate the rest.

ByteChef