Add HINT for COPY TO when WHERE clause is used.
authorFujii Masao <fujii@postgresql.org>
Tue, 2 Sep 2025 23:33:54 +0000 (08:33 +0900)
committerFujii Masao <fujii@postgresql.org>
Tue, 2 Sep 2025 23:35:55 +0000 (08:35 +0900)
commit229911c4bf9a4acfb2b81cff148fd8391e0a577b
tree427b912fcd752371409c67f515b3db87f1e0ed82
parent510777a2d56b5de5f55d3e995c0d0242eb630eb1
Add HINT for COPY TO when WHERE clause is used.

COPY TO does not support a WHERE clause, and currently fails with the error:

    ERROR:  WHERE clause not allowed with COPY TO

Since the intended behavior can be achieved by using
COPY (SELECT ... WHERE ...) TO, this commit adds a HINT
to the error message:

    HINT:  Try the COPY (SELECT ... WHERE ...) TO variant.

This makes the error more informative and helps users
quickly find the alternative usage.

Author: Atsushi Torikoshi <torikoshia@oss.nttdata.com>
Reviewed-by: Jim Jones <jim.jones@uni-muenster.de>
Discussion: https://postgr.es/m/3520c224c5ffac0113aef84a9179f37e@oss.nttdata.com
src/backend/parser/gram.y
src/test/regress/expected/copy2.out