pgsql: Make LATERAL implicit for functions in FROM.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Make LATERAL implicit for functions in FROM.
Date: 2013-01-26 21:19:03
Message-ID: E1TzD9T-0005bR-1H@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Make LATERAL implicit for functions in FROM.

The SQL standard does not have general functions-in-FROM, but it does
allow UNNEST() there (see the <collection derived table> production),
and the semantics of that are defined to include lateral references.
So spec compliance requires allowing lateral references within UNNEST()
even without an explicit LATERAL keyword. Rather than making UNNEST()
a special case, it seems best to extend this flexibility to any
function-in-FROM. We'll still allow LATERAL to be written explicitly
for clarity's sake, but it's now a noise word in this context.

In theory this change could result in a change in behavior of existing
queries, by allowing what had been an outer reference in a function-in-FROM
to be captured by an earlier FROM-item at the same level. However, all
pre-9.3 PG releases have a bug that causes them to match variable
references to earlier FROM-items in preference to outer references (and
then throw an error). So no previously-working query could contain the
type of ambiguity that would risk a change of behavior.

Per a suggestion from Andrew Gierth, though I didn't use his patch.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/2378d79ab29865f59245744beb8f04a3ce56d2ae

Modified Files
--------------
doc/src/sgml/queries.sgml | 20 +++++++++++---
doc/src/sgml/ref/select.sgml | 41 ++++++++++++++++++++---------
src/backend/parser/parse_clause.c | 21 +++++++++++---
src/test/regress/expected/join.out | 37 +++++++++++++++++---------
src/test/regress/expected/rangefuncs.out | 13 ++++++---
src/test/regress/sql/join.sql | 13 ++++++---
src/test/regress/sql/rangefuncs.sql | 2 +-
7 files changed, 101 insertions(+), 46 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Meskes 2013-01-27 12:51:33 pgsql: Made ecpglib use translated messages.
Previous Message Bruce Momjian 2013-01-26 19:52:04 pgsql: Update comments in new DROP IF EXISTS code; commit message updat