7

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?

1 Answer 1

23

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));
Sign up to request clarification or add additional context in comments.

2 Comments

this gives same error psql -U postgres -d postgres -t -A -F"," -c "COPY (SELECT * FROM solrmaster) to '/tmp/solrmastertest.csv' DELIMITER '|' QUOTE '\"' FORCE_QUOTE {(key, components, docnum)} CSV HEADER"
Great answer, the first I'd seen that used with (...) - I didn't realize it needed parentheses around multiple, since ... with delimiter ',' worked without parens

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.