Re: LATERAL - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: LATERAL
Date
Msg-id 1252309425.29289.8.camel@fsopti579.F-Secure.com
Whole thread Raw
In response to LATERAL  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: LATERAL
List pgsql-hackers
On Sun, 2009-09-06 at 23:59 -0400, Robert Haas wrote:
> Based on reading through this discussion, it appears that LATERAL is
> mostly a bit of syntactic sugar that requests that the parser allow
> you to reference tables at the same query level.  Assuming that the
> necessary executor support were present (which it's currently not),
> it's unclear to me why one couldn't simply allow such references
> unconditionally.

Because joins can be reordered, whereas LATERAL creates a kind of
syntactic sequence point for join reordering.  To pick up your example:

> But this doesn't [work]:
> 
> select g, h from generate_series(1,10) g, generate_series(1,g) h;

You need to constrain the order of the from items in some way so the "g"
refers to something well-defined.  That's what LATERAL does.

You could argue that the parser could infer the references and the
resultant join ordering restrictions automatically, but perhaps it was
deemed that an explicit specification would be less error-prone.




pgsql-hackers by date:

Previous
From: Itagaki Takahiro
Date:
Subject: Re: _WIN32_WINNT should be 0x0501 in win32.h
Next
From: Peter Eisentraut
Date:
Subject: Re: Triggers on columns