Using psql to export data
suggest changeData can be exported with COPY or with psql’s output options.
To export the table "user" as delimited text:
psql -p <port> -U <username> -d <database> -A -F <delimiter> -c "<sql to execute>" > <output filename with path>
psql -p 5432 -U postgres -d test_database -A -F ',' -c 'SELECT * FROM "user"' > /home/user/user_data.csv
-A and -F together turn off aligned columns and set the field separator. This is not full CSV: values are not quoted, so an embedded comma will break the file. Use \copy or COPY ... CSV when fields may contain the delimiter. USER is reserved, so quote the table name.
-F is to specify delimiter
-A or --no-align
Switches to unaligned output mode. (The default output mode is otherwise aligned.)
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents