Yacer Saoud
Yacer Saoud

Reputation: 47

postgresql import data to database by columns

I am new to postgresql and I am trying to import my csv data into the database I created. I created a table in my database with a few columns. I would like to import my data to the table while filtering the columns to the ones I created in the database.

An example of my data source:

X Y Z
One Two Three

For example, my columns in the table created: X and Z, so I would like only to import X and Z. I hope I am being clear and sorry for any inconveniences. Thanks

Upvotes: 0

Views: 140

Answers (1)

Josh
Josh

Reputation: 69

You can create a temporary table with all the columns from csv.

Then you can copy the file into the temporary table

copy temp_table (x, y, z) from 'csv_file_path'

After this you can insert into your table from the temporary table

insert into your_table (x, z) select x, z from temp_table

Upvotes: 1

Related Questions