0

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

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

2 Comments

should I write this in public's script or my table's script ? thank you for the answer too!
what do mean by public's script or table's script?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.