Hi, While looking at 1999fe227df, I noticed that the new Assert(refname) in get_variable() can be hit through a rule (v v edge case, fuzz testing):
CREATE TABLE t (a int);
CREATE VIEW v AS SELECT * FROM t;
CREATE RULE v_ins AS ON INSERT TO v DO INSTEAD
INSERT INTO t VALUES (new.a) RETURNING WITH (NEW AS n) n.a;
EXPLAIN (VERBOSE, COSTS OFF)
INSERT INTO v AS new VALUES (1) RETURNING *;
TRAP: failed Assert("refname"), File: "ruleutils.c", Line: 7747
IIUC, the INSERT already uses "new" as its alias, so it has no NEW
alias for RETURNING, and rewriteRuleAction() then copies that empty
alias over the rule's "n". The same seems to happen for OLD, with an
UPDATE rule and UPDATE v AS old.
The attached patch just keeps the rule's alias in that case, and
EXPLAIN then shows "Output: n.a". Thoughts?
Regards,
Ayush
v1-0001-Preserve-RETURNING-aliases-when-rewriting-rules.patch
Description: Binary data
