I had a question surrounding the COPY
command in PostgreSQL. I have a CSV file that I only want to copy some of the columns values into my PostgreSQL table.
Is it possible to do this? I am familiar with using the COPY
command to copy all of the data from a CSV into a table using the header to map to the column names but how is this possible when I only want some of the columns?
Best Answer
Either pre-process the CSV file, or (what I probably would do) import into a temporary copy of the target table and
INSERT
only selected columns in a second step:A temporary table is dropped automatically at the end of the session. If the processing takes longer, use a regular table.