We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
To quickly import a CSV file into a PostgreSQL table:
SET DateStyle = 'ISO, DMY'; -- Set the correct date format
copy mytable (column1, column2) from 'local-file.csv' delimiter ',' csv header; -- Import the files
If you want, you can also stream from stdin
:
SET DateStyle = 'ISO, DMY'; -- Set the correct date format
copy mytable (column1, column2) from STDIN delimiter ',' csv header; -- Import the files
You can then run it from the shell like this:
psql -h remotehost -d remote_mydb -U myuser -c \
"copy mytable (column1, column2) from STDIN with delimiter as ','" \
< /path/to/local/file.csv
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.