Re: BUG #18664: Assert in BeginCopyTo() fails when source DML query rewritten with notifying rule

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Tender Wang <tndrwang(at)gmail(dot)com>
Cc: exclusion(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18664: Assert in BeginCopyTo() fails when source DML query rewritten with notifying rule
Date: 2024-10-21 17:30:26
Message-ID: 1630004.1729531826@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Tender Wang <tndrwang(at)gmail(dot)com> writes:
> PG Bug reporting form <noreply(at)postgresql(dot)org> 于2024年10月21日周一 19:32写道:
>> The following script:
>> CREATE TABLE t(i int);
>> CREATE RULE r AS ON INSERT TO t DO INSTEAD NOTIFY c;
>> COPY (INSERT INTO t VALUES (1)) TO stdout;
>>
>> triggers an Assert in BeginCopyTo():

> I take a quick look. It seems 92e38182d ignored this case.
> I gave a fix that remove the Assert and add an Assert in another if blocks.
> Any thoughts?

I don't like this fix, because the error message is just completely
misleading for this case. "COPY query must have a RETURNING clause"
makes it look like your mistake was to not write

COPY (INSERT INTO t VALUES (1) RETURNING *) TO stdout;

Of course doing that will fix nothing, and you'd still get the exact
same error message, leaving the user quite confused. So I think
it's worth issuing a more specific message.

I also noted somebody's faulty grammar in the nearby message
"DO ALSO rules are not supported for the COPY".

So I think we want the attached. I went back and forth about
whether to make the new message be specifically "COPY query must
not be NOTIFY", but decided that we'd surely forget to update it
if we ever allow any other sort of utility command in rules.
So better to word it generically.

regards, tom lane

Attachment Content-Type Size
v2-fix-bad-assert-in-COPY.patch text/x-diff 3.9 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Alexey Shishkin 2024-10-21 19:16:56 Re: pg_ident.conf + regular expressions issue
Previous Message Alex Richman 2024-10-21 16:32:57 Re: Logical Replica ReorderBuffer Size Accounting Issues