Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uoBGC-00HSSm-FS for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Aug 2025 01:35:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uoBGB-004Zw5-TS for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Aug 2025 01:35:36 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uoBGB-004Zvw-Jm for pgsql-hackers@lists.postgresql.org; Tue, 19 Aug 2025 01:35:36 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1uoBG8-000ZBZ-2Y for pgsql-hackers@lists.postgresql.org; Tue, 19 Aug 2025 01:35:35 +0000 Received: from oss.nttdata.com (localhost [127.0.0.1]) by oss.nttdata.com (Postfix) with ESMTPA id 74EE861BCC for ; Tue, 19 Aug 2025 10:35:29 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at oss.nttdata.com MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=_4908d701b09ab9c08544eb12ac1b1ed5" Date: Tue, 19 Aug 2025 10:35:28 +0900 From: torikoshia To: pgsql-hackers@lists.postgresql.org Subject: COPY TO: provide hint when WHERE clause is used User-Agent: Roundcube Webmail/1.4.11 Message-ID: <3520c224c5ffac0113aef84a9179f37e@oss.nttdata.com> X-Sender: torikoshia@oss.nttdata.com Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --=_4908d701b09ab9c08544eb12ac1b1ed5 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Hi, I saw a user wanted to restrict the rows copied by COPY TO using a WHERE=20 clause, but ran into an error. As you know, COPY FROM supports WHERE, but COPY TO does not: =3D# copy t1 to stdout where i > 5; ERROR: WHERE clause not allowed with COPY TO LINE 1: copy t1 to stdout where i > 5; ^ In such cases, we can do with specifying a query as the target of COPY: =3D# copy (select i from t1 where i > 5) to stdout; However, as shown in the first example, no hint is provided in the error=20 message. For views or others, COPY TO already provides a helpful hint message: =3D# copy v1 to stdout; ERROR: cannot copy from view "v1" HINT: Try the COPY (SELECT ...) TO variant. Considering what the user was trying to do, it might be helpful to=20 provide a similar hint in this case as well. I=E2=80=99ve attached a patch that adds such a hint. What do you think? --=20 Regards, -- Atsushi Torikoshi Seconded from NTT DATA Japan Corporation to SRA OSS K.K. --=_4908d701b09ab9c08544eb12ac1b1ed5 Content-Transfer-Encoding: base64 Content-Type: text/x-diff; name=v1-0001-provide_hint_when_WHERE_is_used.patch Content-Disposition: attachment; filename=v1-0001-provide_hint_when_WHERE_is_used.patch; size=945 RnJvbSBkMWI0ZTIzYTFiMjQ3ODJlOWRlMTZkNzQ4NTA4YzQ2MzU0ZTQyNDIzIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBBdHN1c2hpIFRvcmlrb3NoaSA8dG9yaWtvc2hpYUBvc3MubnR0 ZGF0YS5jb20+CkRhdGU6IFN1biwgMyBBdWcgMjAyNSAxNzo1NTowOSArMDkwMApTdWJqZWN0OiBb UEFUQ0ggdjFdIENPUFkgVE86IHByb3ZpZGUgaGludCB3aGVuIFdIRVJFIGNsYXVzZSBpcyB1c2Vk CgpQcm92aWRlIGEgaGludCBzdWdnZXN0aW5nIENPUFkgcXVlcnkgVE8gd2hlbiBhIFdIRVJFIGNs YXVzZQppcyBzcGVjaWZpZWQsIHNpbWlsYXIgdG8gdGhlIGhpbnQgYWxyZWFkeSBnaXZlbiBmb3Ig dmlld3Mgb3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