This is a follow-up question from this answer for "Save PL/pgSQL output from PostgreSQL to a CSV file".
I need to write a client-side CSV file using psql's copy
command. A one liner works:
db=> copy (select 1 AS foo) to 'bar.csv' csv header
COPY 1
However, I have long queries that span several lines. I don't need to show the query, as I can't seem to extend this past one line without a parse error:
db=> copy (
copy: parse error at end of line
db=> copy ( \
copy: parse error at end of line
db=> copy ("
copy: parse error at end of line
db=> copy "(
copy: parse error at end of line
db=> copy \
copy: parse error at end of line
Is it possible to use copy
with a query that spans multiple lines? I'm using psql on Windows.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…