Skip to content

Instantly share code, notes, and snippets.

@miceno
Created February 2, 2018 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miceno/311188ed34efa0ad13b3b29c70d13238 to your computer and use it in GitHub Desktop.
Save miceno/311188ed34efa0ad13b3b29c70d13238 to your computer and use it in GitHub Desktop.
Export and import CSV in postgres
-- On the server.
-- \copy is run on the client side, so if you run in your local machine to connect to the remote
-- server, you will transfer the results probably in plain. So better run it on local.
\copy (Select * From sns_log where received > '2018-01-01') To '/tmp/log-20180101.csv' With CSV delimiter ','
-- On the client side.
\COPY sns_log FROM 'log-20180101.csv' WITH delimiter as ',' csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment