]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix mishandling of OLD/NEW references in subqueries in rule actions.
authorDean Rasheed <dean.a.rasheed@gmail.com>
Sat, 25 Feb 2023 14:48:08 +0000 (14:48 +0000)
committerDean Rasheed <dean.a.rasheed@gmail.com>
Sat, 25 Feb 2023 14:48:08 +0000 (14:48 +0000)
commit79f194cc0144fad07fa18c4b2a5f32bce9035ee0
tree8e9f97c7ee0543a816b158a6beb54bbd310e1ee0
parent44dbc960f6711e32118a8da71f251d65e0630caa
Fix mishandling of OLD/NEW references in subqueries in rule actions.

If a rule action contains a subquery that refers to columns from OLD
or NEW, then those are really lateral references, and the planner will
complain if it sees such things in a subquery that isn't marked as
lateral. However, at rule-definition time, the user isn't required to
mark the subquery with LATERAL, and so it can fail when the rule is
used.

Fix this by marking such subqueries as lateral in the rewriter, at the
point where they're used.

Dean Rasheed and Tom Lane, per report from Alexander Lakhin.
Back-patch to all supported branches.

Discussion: https://postgr.es/m/5e09da43-aaba-7ea7-0a51-a2eb981b058b%40gmail.com
src/backend/rewrite/rewriteHandler.c
src/test/regress/expected/rules.out
src/test/regress/sql/rules.sql