Re: BUG #15645: \COPY command not printing output in batch mode

From: "Daniel Verite" <daniel(at)manitou-mail(dot)org>
To: sandeshyapuram(at)gmail(dot)com,pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #15645: \COPY command not printing output in batch mode
Date: 2019-02-20 14:38:23
Message-ID: eee511c5-0afc-4d0e-adaf-86e7977514d3@manitou-mail.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form wrote:

> I am trying to truncate a table and copy data into the same table using
> \copy. In this process, I need to print number of rows deleted and copied.
>
> I am using this command:
> echo -e "begin; delete from test; \\\copy test from test.csv CSV HEADER;
> end;" | psql -hlocalhost -dpostgres -Upostgres

As answered at [1] where it was asked as a question,
it's not a bug, but the effect of \copy processing the whole line,
as documented:

"Unlike most other meta-commands, the entire remainder of the line
is always taken to be the arguments of \copy"

plus the fact that from the COPY + END commands executed in the
same compound statement, only the last result is handled/displayed
by psql, which is also known and documented.

Suggested workarounds:
1. use psql -1 instead of adding your own BEGIN/END commands.
2. use the heredoc syntax for multi-line SQL scripts embedded into
shell commands.

[1] https://dba.stackexchange.com/questions/230230/

Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2019-02-20 16:10:56 BUG #15646: Inconsistent behavior for current_setting/set_config
Previous Message Jeremy Finzel 2019-02-20 14:24:59 Re: Segmentation Fault in logical decoding get/peek API