From: Daniel Verite <daniel@manitou-mail.org>
To: sandeshyapuram@gmail.com
To: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #15645: \COPY command not printing output in batch mode
Date: Wed, 20 Feb 2019 15:38:23 +0100
Message-ID: <eee511c5-0afc-4d0e-adaf-86e7977514d3@manitou-mail.org> (raw)
In-Reply-To: <15645-b22cf5a1fbbd37c3@postgresql.org>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: daniel@manitou-mail.org, sandeshyapuram@gmail.com
Subject: Re: BUG #15645: \COPY command not printing output in batch mode
In-Reply-To: <eee511c5-0afc-4d0e-adaf-86e7977514d3@manitou-mail.org>
References: <15645-b22cf5a1fbbd37c3@postgresql.org> <eee511c5-0afc-4d0e-adaf-86e7977514d3@manitou-mail.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox