Re: LATERAL

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: LATERAL
Date: 2009-09-07 07:43:45
Message-ID: 1252309425.29289.8.camel@fsopti579.F-Secure.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

  • LATERAL at 2009-09-07 03:59:22 from Robert Haas

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2009-09-07 07:53:57 Re: Triggers on columns
Previous Message Itagaki Takahiro 2009-09-07 05:53:57 Re: _WIN32_WINNT should be 0x0501 in win32.h