Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5e94f61

Browse files
committed
Fix wrong assertion and poor error messages in "COPY (query) TO".
If the query is rewritten into a NOTIFY command by a DO INSTEADrule, we'd get an assertion failure, or in non-assert buildsissue a rather confusing error message. Improve that.Also fix a longstanding grammar mistake in a nearby error message.Per bug #18664 from Alexander Lakhin. Back-patch to all supportedbranches.Tender Wang and Tom LaneDiscussion:https://postgr.es/m/18664-ffd0ebc2386598df@postgresql.org
1 parent520ec24 commit5e94f61

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

‎src/backend/commands/copyto.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ BeginCopyTo(ParseState *pstate,
466466
if (q->querySource==QSRC_NON_INSTEAD_RULE)
467467
ereport(ERROR,
468468
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
469-
errmsg("DO ALSO rules are not supported fortheCOPY")));
469+
errmsg("DO ALSO rules are not supported for COPY")));
470470
}
471471

472472
ereport(ERROR,
@@ -483,7 +483,11 @@ BeginCopyTo(ParseState *pstate,
483483
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
484484
errmsg("COPY (SELECT INTO) is not supported")));
485485

486-
Assert(query->utilityStmt==NULL);
486+
/* The only other utility command we could see is NOTIFY */
487+
if (query->utilityStmt!=NULL)
488+
ereport(ERROR,
489+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
490+
errmsg("COPY query must not be a utility command")));
487491

488492
/*
489493
* Similarly the grammar doesn't enforce the presence of a RETURNING

‎src/test/regress/expected/copydml.out

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ ERROR: DO INSTEAD NOTHING rules are not supported for COPY
3838
drop rule qqq on copydml_test;
3939
create rule qqq as on insert to copydml_test do also delete from copydml_test;
4040
copy (insert into copydml_test default values) to stdout;
41-
ERROR: DO ALSO rules are not supported fortheCOPY
41+
ERROR: DO ALSO rules are not supported for COPY
4242
drop rule qqq on copydml_test;
4343
create rule qqq as on insert to copydml_test do instead (delete from copydml_test; delete from copydml_test);
4444
copy (insert into copydml_test default values) to stdout;
@@ -54,7 +54,7 @@ ERROR: DO INSTEAD NOTHING rules are not supported for COPY
5454
drop rule qqq on copydml_test;
5555
create rule qqq as on update to copydml_test do also delete from copydml_test;
5656
copy (update copydml_test set t = 'f') to stdout;
57-
ERROR: DO ALSO rules are not supported fortheCOPY
57+
ERROR: DO ALSO rules are not supported for COPY
5858
drop rule qqq on copydml_test;
5959
create rule qqq as on update to copydml_test do instead (delete from copydml_test; delete from copydml_test);
6060
copy (update copydml_test set t = 'f') to stdout;
@@ -70,7 +70,7 @@ ERROR: DO INSTEAD NOTHING rules are not supported for COPY
7070
drop rule qqq on copydml_test;
7171
create rule qqq as on delete to copydml_test do also insert into copydml_test default values;
7272
copy (delete from copydml_test) to stdout;
73-
ERROR: DO ALSO rules are not supported fortheCOPY
73+
ERROR: DO ALSO rules are not supported for COPY
7474
drop rule qqq on copydml_test;
7575
create rule qqq as on delete to copydml_test do instead (insert into copydml_test default values; insert into copydml_test default values);
7676
copy (delete from copydml_test) to stdout;
@@ -80,6 +80,10 @@ create rule qqq as on delete to copydml_test where old.t <> 'f' do instead inser
8080
copy (delete from copydml_test) to stdout;
8181
ERROR: conditional DO INSTEAD rules are not supported for COPY
8282
drop rule qqq on copydml_test;
83+
create rule qqq as on insert to copydml_test do instead notify copydml_test;
84+
copy (insert into copydml_test default values) to stdout;
85+
ERROR: COPY query must not be a utility command
86+
drop rule qqq on copydml_test;
8387
-- triggers
8488
create function qqq_trig() returns trigger as $$
8589
begin

‎src/test/regress/sql/copydml.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ create rule qqq as on delete to copydml_test where old.t <> 'f' do instead inser
6666
copy (deletefrom copydml_test) to stdout;
6767
droprule qqqon copydml_test;
6868

69+
createruleqqqason insert to copydml_test do instead notify copydml_test;
70+
copy (insert into copydml_test defaultvalues) to stdout;
71+
droprule qqqon copydml_test;
72+
6973
-- triggers
7074
createfunctionqqq_trig() returns triggeras $$
7175
begin

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp