wlodarmt
wlodarmt

Reputation: 1

Importing non formatted CSV into a Postgres Database

I am trying to import a csv into postgres.

I have my tables set up and my csv file is formatted in a way such that it is clear where the data I need is, but it is not formatted in the same way as the tables.

For a simple example: I have

Table1 with field1 field2 and field3

Table2 with field1 and field2

my csv has value1,value2,value3,value4

I want to load value1 into Table1 field2, value2 into Table2 field1, and value3 into Table1 field3.

I was wondering if there exists any tool, within postgres or without for handling the mapping and import, or is this something I would need to write a separate script or program for. If the second, any suggestions would be welcome.

Thank you very much!

Upvotes: 0

Views: 172

Answers (1)

Jeremy
Jeremy

Reputation: 6723

Create a temporary table with the same structure as your CSV, load the CSV data into this table, and then insert data into table1 and table2 from the temporary table.

Upvotes: 1

Related Questions