Copy a few of the columns of a csv file into a table

后端 未结 7 487
难免孤独
难免孤独 2020-11-28 03:39

I have a CSV file with 10 columns. After creating a PostgreSQL table with 4 columns, I want to copy some of 10 columns into the table.

the columns of my CSV table ar

7条回答
  •  再見小時候
    2020-11-28 04:00

    You could take James Brown's suggestion further and do, all in one line:

    $ awk -F ',' '{print $2","$5","$7","$10}' file | psql -d db -c "\copy MyTable from STDIN csv header"
    

提交回复
热议问题