From 9c4a57af944c66cdae6d10fde019f7e8c6d66367 Mon Sep 17 00:00:00 2001 From: zhubin79 <18784715772@163.com> Date: Wed, 10 Jul 2024 18:43:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dcopy=E8=AF=AD=E5=8F=A5WHEN?= =?UTF-8?q?=E8=A2=ABwhen=5Fexpr=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=B3=A8?= =?UTF-8?q?=E5=85=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/backend/parser/gram.y | 3 +++ src/test/regress/expected/copyselect.out | 7 +++++++ src/test/regress/sql/copyselect.sql | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/src/common/backend/parser/gram.y b/src/common/backend/parser/gram.y index bf6dde2f9..9cb9518da 100644 --- a/src/common/backend/parser/gram.y +++ b/src/common/backend/parser/gram.y @@ -6151,6 +6151,9 @@ copy_generic_opt_list: copy_generic_opt_elem: ColLabel copy_generic_opt_arg { + /* Character "when_expr" may be injected as "COPY ... WHEN ... "*/ + if (pg_strcasecmp($1, "when_expr") == 0) + ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("option \"%s\" not recognized", $1))); $$ = makeDefElem($1, $2); } ; diff --git a/src/test/regress/expected/copyselect.out b/src/test/regress/expected/copyselect.out index 1aaa75897..1fdfa3b56 100644 --- a/src/test/regress/expected/copyselect.out +++ b/src/test/regress/expected/copyselect.out @@ -60,6 +60,13 @@ ERROR: syntax error at or near "(" LINE 1: copy (select * from test1) (t,id) to stdout; ^ -- +-- Test when_expr +-- +copy (select * from test1) to stdout with (when_expr); -- error +ERROR: option "when_expr" not recognized +copy (select * from test1) to stdout with (when_expr''); -- error +ERROR: option "when_expr" not recognized +-- -- Test JOIN -- copy (select * from test1 join test2 using (id) order by 1) to stdout; diff --git a/src/test/regress/sql/copyselect.sql b/src/test/regress/sql/copyselect.sql index 92d64c5c6..34cfb8265 100644 --- a/src/test/regress/sql/copyselect.sql +++ b/src/test/regress/sql/copyselect.sql @@ -47,6 +47,11 @@ copy (select * from test1) from stdin; -- copy (select * from test1) (t,id) to stdout; -- +-- Test when_expr +-- +copy (select * from test1) to stdout with (when_expr); -- error +copy (select * from test1) to stdout with (when_expr''); -- error +-- -- Test JOIN -- copy (select * from test1 join test2 using (id) order by 1) to stdout;