Wednesday, May 10, 2017

PostgreSQL: copy in and out

Source:
Import from local CSV to remote DB:
psql -Upostgres -h my_host -d my_db -c "\copy public.nwkmonitor from '/tmp/in.csv' with delimiter as ',' null as '';"
Export from remote DB to local CSV:
psql -Upostgres -h my_host -d my_db -c "\copy public.nwkmonitor2 to '/tmp/out.csv' csv delimiter as ',' header;"