From d1b4e23a1b24782e9de16d748508c46354e42423 Mon Sep 17 00:00:00 2001
From: Atsushi Torikoshi <torikoshia@oss.nttdata.com>
Date: Sun, 3 Aug 2025 17:55:09 +0900
Subject: [PATCH v1] COPY TO: provide hint when WHERE clause is used

Provide a hint suggesting COPY query TO when a WHERE clause
is specified, similar to the hint already given for views or others.

---
 src/backend/parser/gram.y | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index db43034b9db..9fd48acb1f8 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -3442,6 +3442,7 @@ CopyStmt:	COPY opt_binary qualified_name opt_column_list
 						ereport(ERROR,
 								(errcode(ERRCODE_SYNTAX_ERROR),
 								 errmsg("WHERE clause not allowed with COPY TO"),
+								 errhint("Try the COPY (SELECT ... WHERE ...) TO variant."),
 								 parser_errposition(@11)));
 
 					n->options = NIL;
-- 
2.48.1

