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 1i3iYp-0003jg-NK for pgsql-general@arkaria.postgresql.org; Fri, 30 Aug 2019 15:11: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 1i3iYo-0007aI-Bx for pgsql-general@arkaria.postgresql.org; Fri, 30 Aug 2019 15:11:34 +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 1i3iYo-0007aB-28 for pgsql-general@lists.postgresql.org; Fri, 30 Aug 2019 15:11:34 +0000 Received: from mail.appl-ecosys.com ([50.126.108.78]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i3iYl-0000xM-Kv for pgsql-general@postgresql.org; Fri, 30 Aug 2019 15:11:33 +0000 Received: from salmo.appl-ecosys.com (salmo.appl-ecosys.com [192.168.55.1]) by mail.appl-ecosys.com (Postfix) with ESMTP id 8003A9939A for ; Fri, 30 Aug 2019 08:11:28 -0700 (PDT) Date: Fri, 30 Aug 2019 08:11:28 -0700 (PDT) From: Rich Shepard Reply-To: Rich Shepard To: pgsql-general@postgresql.org Subject: Escape parentheses in aggregate function Message-ID: User-Agent: Alpine 2.20 (LNX 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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'; Do I write sumE'('count_valueE')', sum\(count_value\), or something else? TIA, Rich