diff --git a/src/common/backend/parser/gram.y b/src/common/backend/parser/gram.y index 7862cc7bf..f0b857684 100644 --- a/src/common/backend/parser/gram.y +++ b/src/common/backend/parser/gram.y @@ -6165,6 +6165,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;