Reputation: 395
I try to perform follow command
psql -c '\\COPY (SELECT file_name, status, reported, operator_id, load_dt AT TIME ZONE GMT FROM mytable) TO STDOUT' > myfile
I receive an error
ERROR: column "gmt" does not exist
LINE 1: ...atus, reported, operator_id, load_dt AT TIME ZONE GMT FROM p...
Upvotes: 0
Views: 526
Reputation: 1928
Can this be of help for you? This is on windows machine. Consider that query command might need modification, depending of what your PC operating system is.
psql -U postgres -d aambackend_dev -c "SELECT \"createdAt\"::timestamp without time zone FROM \"User\" limit(2)" -H -o "D:\xxx1.html"
For more info you can refer to: https://www.postgresql.org/docs/13/app-psql.html
Note 1: depending of column i want to select, for majority of columns i don't need escape backslash character. Only for columns of type timestamp with/out time zone i needed to add backslash for quotes.
Note 2: semicolon at the end was not needed in this case (in some other commands and cases it is necessary)
If you wish CSV format:
psql -U postgres -d aambackend_dev -c "SELECT "email",\"createdAt\"::timestamp without time zone FROM \"User\" limit(2)" -o "D:\xx2212.csv"
Upvotes: 1