BT3
BT3

Reputation: 395

Error using select statement in psql command

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

Answers (1)

Stefan
Stefan

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"

  • -U postgres - user
  • -d typeorm - my database to which i want to connect
  • -c ... - my query command
  • -H format html, -o output file

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)

This is my exported file: enter image description here

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"enter image description here

Upvotes: 1

Related Questions