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 1i3ifJ-00049T-EM for pgsql-general@arkaria.postgresql.org; Fri, 30 Aug 2019 15:18:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i3ifH-00073Q-Of for pgsql-general@arkaria.postgresql.org; Fri, 30 Aug 2019 15:18:15 +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 1i3ifH-0006jv-8p for pgsql-general@lists.postgresql.org; Fri, 30 Aug 2019 15:18:15 +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 1i3ifE-0001I4-W7 for pgsql-general@postgresql.org; Fri, 30 Aug 2019 15:18:14 +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 x7UFI67c026322; Fri, 30 Aug 2019 11:18:06 -0400 From: Tom Lane To: Rich Shepard cc: pgsql-general@postgresql.org Subject: Re: Escape parentheses in aggregate function In-reply-to: References: Comments: In-reply-to Rich Shepard message dated "Fri, 30 Aug 2019 08:11:28 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <26320.1567178286.1@sss.pgh.pa.us> Date: Fri, 30 Aug 2019 11:18:06 -0400 Message-ID: <26321.1567178286@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Rich Shepard writes: > I want to copy query results to a text file and there's an aggregate > function in the SELECT expression. One of the aggregate function's > parentheses seems to end the \copy() function and I don't know how best to > write the statement. A minimal example: > \copy(select count_value, sum(count_value) > from table_name) to 'output_file.txt'; 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 commands continue across lines. regards, tom lane