Re: could not find replacement targetlist entry for attno -6

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: could not find replacement targetlist entry for attno -6
Date: 2026-01-27 11:55:00
Message-ID: CAEZATCWqKqAsn_NkG7+_vgeOH6kfQe9DDQr7usPvNj6zJ_BPZg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, 27 Jan 2026 at 08:27, jian he <jian(dot)universality(at)gmail(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2026-01-27 11:59:18 Re: pg_upgrade: optimize replication slot caught-up check
Previous Message Fujii Masao 2026-01-27 11:32:57 logical apply worker's lock waits in subscriber can stall checkpointer in publisher