I'm trying to export a table to CSV and force quoting of two columns.
I've tried the following command:
COPY hotel_position_daily TO '/home/ubuntu/export/hotel_position_daily.csv' CSV HEADER FORCE_QUOTE hotelname, city;
which resulted in
ERROR: syntax error at or near "FORCE_QUOTE"
LINE 1: ...buntu/export/hotel_position_daily.csv' CSV HEADER FORCE_QUOT...
and I've tried
COPY hotel_position_daily TO '/home/ubuntu/export/hotel_position_daily.csv' WITH (FORMAT CSV, HEADER, FORCE_QUOTE hotelname, city);
which resulted in
ERROR: argument to option "force_quote" must be a list of column names
what am I doing wrong?
Description. COPY moves data between PostgreSQL tables and standard file-system files. COPY TO copies the contents of a table to a file, while COPY FROM copies data from a file to a table (appending the data to whatever is in the table already). COPY TO can also copy the results of a SELECT query.
If you COPY data into a table already containing data, the new data will be appended. If you COPY TO a file already containing data, the existing data will be overwritten.
The easiest but the most efficient way to export data from a Postgres table to a CSV file is by using the COPY command. COPY command generates a CSV file on the Database Server. You can export the entire table or the results of a query to a CSV file with the COPY TO command.
I found the solution to be
COPY hotel_position_daily TO '/home/ubuntu/export/hotel_position_daily.csv' WITH (FORMAT CSV, HEADER, FORCE_QUOTE(hotelname, city));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With