BUG #16661: Changing columns after the rule is created leads to an error when the RETURNING is used

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: drakonard(at)gmail(dot)com
Subject: BUG #16661: Changing columns after the rule is created leads to an error when the RETURNING is used
Date: 2020-10-08 12:26:59
Message-ID: 16661-01a98a6c58c8054a@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 16661
Logged by: Konstantin Dyachenko
Email address: drakonard(at)gmail(dot)com
PostgreSQL version: 12.4
Operating system: Debian
Description:

The SQL:

CREATE TABLE rule_bug_table (
id serial NOT NULL PRIMARY KEY,
archived boolean NOT NULL
);

CREATE OR REPLACE RULE rule_bug_table__archive_instead_of_delete__rule
AS ON DELETE TO rule_bug_table
DO INSTEAD
UPDATE rule_bug_table
SET archived = true
WHERE rule_bug_table."id" = OLD."id"
RETURNING OLD.*;

ALTER TABLE rule_bug_table ADD COLUMN select_allowed boolean NOT NULL
DEFAULT (false);

DELETE FROM rule_bug_table WHERE id = 1 RETURNING *;

gives an error "could not find replacement targetlist entry for attno 3".
Meaning rule cannot find a column with number 3 (select_allowed column).

In other words if after rule was created any column is changed usage of
RETURNING leads to an error.

The workaround is to recreated rule after the table's column was altered.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2020-10-08 15:14:23 Re: WIDTH_BUCKET inconsistency
Previous Message Martin Visser 2020-10-08 10:57:27 WIDTH_BUCKET inconsistency