Re: could not find replacement targetlist entry for attno -6 - Mailing list pgsql-hackers

From Dean Rasheed
Subject Re: could not find replacement targetlist entry for attno -6
Date
Msg-id CAEZATCWqKqAsn_NkG7+_vgeOH6kfQe9DDQr7usPvNj6zJ_BPZg@mail.gmail.com
Whole thread Raw
In response to could not find replacement targetlist entry for attno -6  (jian he <jian.universality@gmail.com>)
List pgsql-hackers
On Tue, 27 Jan 2026 at 08:27, jian he <jian.universality@gmail.com> 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



pgsql-hackers by date:

Previous
From: Fujii Masao
Date:
Subject: logical apply worker's lock waits in subscriber can stall checkpointer in publisher
Next
From: Amit Kapila
Date:
Subject: Re: pg_upgrade: optimize replication slot caught-up check