Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gwT19-0007CO-Ka for pgsql-bugs@arkaria.postgresql.org; Wed, 20 Feb 2019 14:38:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gwT17-0002du-FP for pgsql-bugs@arkaria.postgresql.org; Wed, 20 Feb 2019 14:38:33 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gwT17-0002dm-8i for pgsql-bugs@lists.postgresql.org; Wed, 20 Feb 2019 14:38:33 +0000 Received: from mail.verite.pro ([185.16.44.216]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gwT14-0000C1-QU for pgsql-bugs@lists.postgresql.org; Wed, 20 Feb 2019 14:38:32 +0000 Received: from genius-map.net (verite.pro [195.154.189.246]) by mail.verite.pro (Postfix) with ESMTP id 2FCA18C001C; Wed, 20 Feb 2019 15:33:22 +0100 (CET) Received: by genius-map.net (Postfix, from userid 1001) id 8650E38A2AD8; Wed, 20 Feb 2019 15:38:27 +0100 (CET) Content-Type: text/plain; charset="iso-8859-15" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: BUG #15645: \COPY command not printing output in batch mode From: "Daniel Verite" To: sandeshyapuram@gmail.com,pgsql-bugs@lists.postgresql.org In-Reply-To: <15645-b22cf5a1fbbd37c3@postgresql.org> Date: Wed, 20 Feb 2019 15:38:23 +0100 Message-Id: X-Mailer: Manitou v1.7.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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. >=20 > 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,=20 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, --=20 Daniel V=E9rit=E9 PostgreSQL-powered mailer: http://www.manitou-mail.org Twitter: @DanielVerite