Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3685ad6

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 INSTEAD rule, we'd get an assertion failure, or in non-assert builds issue 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 supported branches. Tender Wang and Tom Lane Discussion: https://postgr.es/m/18664-ffd0ebc2386598df@postgresql.org
1 parent 234f6d0 commit 3685ad6

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/backend/commands/copyto.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ BeginCopyTo(ParseState *pstate,
475475
if (q->querySource == QSRC_NON_INSTEAD_RULE)
476476
ereport(ERROR,
477477
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
478-
errmsg("DO ALSO rules are not supported for the COPY")));
478+
errmsg("DO ALSO rules are not supported for COPY")));
479479
}
480480

481481
ereport(ERROR,
@@ -492,7 +492,11 @@ BeginCopyTo(ParseState *pstate,
492492
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
493493
errmsg("COPY (SELECT INTO) is not supported")));
494494

495-
Assert(query->utilityStmt == NULL);
495+
/* The only other utility command we could see is NOTIFY */
496+
if (query->utilityStmt != NULL)
497+
ereport(ERROR,
498+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
499+
errmsg("COPY query must not be a utility command")));
496500

497501
/*
498502
* Similarly the grammar doesn't enforce the presence of a RETURNING

src/test/regress/expected/copydml.out

+7-3
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 for the COPY
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 for the COPY
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 for the COPY
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

+4
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 (delete from copydml_test) to stdout;
6767
drop rule qqq on copydml_test;
6868

69+
create rule qqq as on insert to copydml_test do instead notify copydml_test;
70+
copy (insert into copydml_test default values) to stdout;
71+
drop rule qqq on copydml_test;
72+
6973
-- triggers
7074
create function qqq_trig() returns trigger as $$
7175
begin

0 commit comments

Comments
 (0)