On Tue, 27 Jan 2026 at 08:27, jian he <[email protected]> wrote:
>
> While reviewing ON CONFLICT DO SELECT, I found an elog(ERROR) behavior, which
> may a bug.

Hmm, AFAICS this has never worked.

Here's a simpler example (taking ON CONFLICT out of the equation,
since it has nothing to do with that):

DROP TABLE IF EXISTS foo, bar;
CREATE TABLE foo (a int);
CREATE TABLE bar (a int);
CREATE RULE foo_ins AS ON INSERT TO foo
  DO INSTEAD INSERT INTO bar VALUES (new.a) RETURNING *;

INSERT INTO foo VALUES (1) RETURNING tableoid, a;

This gives the same error, because tableoid (or any other system
attribute) is not in the rule's RETURNING list, and so cannot be
returned by the outer query. Also, there's no way for the user to add
support for returning system attributes, because the rule's RETURNING
list must have the same number (and types) of (user) columns as the
relation the rule is on.

Arguably then, this is correct behaviour, within the limitations of
the rules system, although the error message is not very friendly.

Given the near-deprecated nature of rules, it's also arguable that
it's not worth trying to fix this, except perhaps to improve the error
message.

Regards,
Dean


Reply via email to