Last active
October 18, 2021 07:04
-
-
Save braynm/f3b65417bcdbf6190424e5f422cb628b to your computer and use it in GitHub Desktop.
copy from|to csv in postgresql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Save without header | |
copy ((select "name", "email from "user") to '/absolute-path-to-directory/filename.csv' delimiter ',' csv; | |
-- Save with header | |
copy ((select "name", "email from "user") to '/absolute-path-to-directory/filename.csv' delimiter ',' csv header; | |
-- When having issue `must be superuser or a member of pg_write_server_files role COPY to a file`, add a `\` in front of `copy` | |
\copy ((select "name", "email from "user") to '/absolute-path-to-directory/filename.csv' delimiter ',' csv; | |
-- copy csv to table | |
\copy "user" ("organizationId") from '<enter path>' delimiter ',' csv; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment