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 1i3kFZ-0000a7-H1 for pgsql-general@arkaria.postgresql.org; Fri, 30 Aug 2019 16:59:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i3kEZ-0008Gc-6A for pgsql-general@arkaria.postgresql.org; Fri, 30 Aug 2019 16:58:47 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i3kEY-0008GV-Ox for pgsql-general@lists.postgresql.org; Fri, 30 Aug 2019 16:58:46 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1i3kEV-00022j-Pr for pgsql-general@postgresql.org; Fri, 30 Aug 2019 16:58:45 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x7UGwdkc030962; Fri, 30 Aug 2019 12:58:39 -0400 From: Tom Lane To: Rich Shepard cc: pgsql-general@postgresql.org Subject: Re: Escape parentheses in aggregate function In-reply-to: References: <26321.1567178286@sss.pgh.pa.us> Comments: In-reply-to Rich Shepard message dated "Fri, 30 Aug 2019 09:20:34 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <30960.1567184319.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 30 Aug 2019 12:58:39 -0400 Message-ID: <30961.1567184319@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Rich Shepard writes: > On Fri, 30 Aug 2019, Tom Lane wrote: >> I think your problem is the line break, not the parentheses. psql knows >> how to count parens, but it has no concept of letting backslash command= s >> continue across lines. > Interesting. I've adopted separating select statements by their expressi= ons > as it makes it easier for me to get it right, or fix it. However, I can = put > it all on a single line once I know the syntax is correct and I add the > \copy() function. FWIW, if you're running a current release then there's a reasonable alternative for writing multi-line COPY-from-query commands; see commit log below. regards, tom lane Author: Tom Lane Branch: master Release: REL_12_BR [6d3ede5f1] 2019-01-26 14:15:42 -0500 Branch: REL_11_STABLE Release: REL_11_2 [2c50c9f23] 2019-01-26 14:15:42 -0= 500 Branch: REL_10_STABLE Release: REL_10_7 [8e97a97b3] 2019-01-26 14:15:42 -0= 500 Branch: REL9_6_STABLE Release: REL9_6_12 [ae4c7d5ab] 2019-01-26 14:15:42 -= 0500 Branch: REL9_5_STABLE Release: REL9_5_16 [cda1e27fb] 2019-01-26 14:15:42 -= 0500 Fix psql's "\g target" meta-command to work with COPY TO STDOUT. = Previously, \g would successfully execute the COPY command, but the target specification if any was ignored, so that the data was always dumped to the regular query output target. This seems like a clear bug, so let's not just fix it but back-patch it. = While at it, adjust the documentation for \copy to recommend "COPY ... TO STDOUT \g foo" as a plausible alternative. = Back-patch to 9.5. The problem exists much further back, but the code associated with \g was refactored enough in 9.5 that we'd need a significantly different patch for 9.4, and it doesn't seem worth the trouble. = Daniel V=C3=A9rit=C3=A9, reviewed by Fabien Coelho = Discussion: https://postgr.es/m/15dadc39-e050-4d46-956b-dcc4ed098753@m= anitou-mail.org