WIP: convert plpgsql to using parser hooks
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-hackers@postgreSQL.org
Date: 2009-11-06T14:43:17Z
Lists: pgsql-hackers
Attachments
- plpgsql-uses-hooks-1.patch (text/x-patch) patch
The attached patch makes the basic cutover from inserting plpgsql variables into SQL expressions by textual substitution, to handling them via parser hooks. Currently I only have the pre_columnref hook written, so only the "backwards compatible" semantics are available. However this already makes two significant changes compared to before: 1. plpgsql will no longer attempt to substitute variables where they can't sensibly go, such as table names or column aliases. 2. variable names can't match reserved words unless quoted (notice the one necessary change in the regression tests). I realized though that the namespace mechanism needs further adjustment. As-is, the scope of a variable declaration is its whole block, which is wrong. Consider declare x int; begin ... declare y int := x+1; x int := 4; The second declaration of x will probably capture the "x" reference in y's default, which it should not. What I think I will do about this is to abandon the notion of an array-per-namespace altogether, and turn the namespace data structure into simple chains of individual names. Instead of linking SQL expressions to the topmost visible namespace, they'll link to the last-added variable that they can see. This gives per-variable granularity of visibility, which is what we need to make this type of thing work as expected. regards, tom lane