Re: BUG #17803: Rule "ALSO INSERT ... SELECT ..." fails to substitute default values
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Dean Rasheed <dean.a.rasheed@gmail.com>
Cc: Alexander Lakhin <exclusion@gmail.com>, pgsql-bugs@lists.postgresql.org
Date: 2023-02-24T16:53:45Z
Lists: pgsql-bugs
Dean Rasheed <dean.a.rasheed@gmail.com> writes:
> Here's an updated patch, now with test cases involving both OLD and
> NEW references.
It might be worth doing
+ if (rte->rtekind == RTE_SUBQUERY && !rte->lateral &&
+ contain_vars_of_level((Node *) rte->subquery, 1))
+ rte->lateral = true;
so as to save the expense of contain_vars_of_level() when the flag
is already set. However, it's arguable that no users would bother
with writing LATERAL, so this might be pointless.
More importantly, I think the comment could do with a bit more
information. Maybe like
/*
+ * Mark any subquery RTEs in the rule action as LATERAL if they contain
+ * Vars referring to the current query level (references to NEW/OLD).
+ * Those really are lateral references, but we've historically not
+ * required users to mark such subqueries with LATERAL explicitly.
+ * But the planner will complain if such Vars exist in a non-LATERAL
+ * subquery, so we have to fix things up here.
+ */
That might be overly verbose, but I think it's good to memorialize this
sort of info.
LGTM otherwise.
regards, tom lane
Commits
-
Fix mishandling of OLD/NEW references in subqueries in rule actions.
- 79f194cc0144 11.20 landed
- 4fd093af7186 12.15 landed
- 39ad791e8510 13.11 landed
- 27ff93d18c2b 14.8 landed
- 8e5b4e0013a8 15.3 landed
- a7d71c41dbd6 16.0 landed
-
Fix multi-row DEFAULT handling for INSERT ... SELECT rules.
- e68b133c30e2 11.20 landed
- 98b83b734982 12.15 landed
- 226da3d47670 13.11 landed
- f0423bea7f0a 14.8 landed
- 940b5474365f 15.3 landed
- 75c737636b8a 16.0 landed
-
Fix DEFAULT-handling in multi-row VALUES lists for updatable views.
- 41531e42d34f 12.0 cited