Re: BUG #12000: "CROSS JOIN" not equivalent to ","

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: kunert(at)cms(dot)hu-berlin(dot)de
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #12000: "CROSS JOIN" not equivalent to ","
Date: 2014-11-18 17:29:03
Message-ID: 2468.1416331743@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

kunert(at)cms(dot)hu-berlin(dot)de writes:
> Still not sure if this is really a bug, but I could not find a good
> explanation for the following behaviour:

> According to the documentation
> http://www.postgresql.org/docs/9.3/static/queries-table-expressions.html
> (7.2.1.1):
> "FROM T1 CROSS JOIN T2 is equivalent to FROM T1, T2"

> However, in the following example the SQL-Query using "CROSS JOIN" works,
> while the usage of "," results in an invalid reference:

It's not a bug. The quoted statement is correct as far as it goes,
but what it fails to point out is that CROSS JOIN has a different
syntactic priority from ",", which matters when you have more than
two tables. Fully parenthesized, your examples would look like

> from
> ((table1 a cross join table1 b)
> left outer join table2 c on a.x = y and b.x = z);

> from
> table1 a
> , (table1 b left outer join table2 c on a.x = y and b.x = z);

so that table "a" is within the scope of the ON clause in the first case
but not the second.

I'm not sure we ought to dive into these syntactic details right at
that point in the manual, though; it's not really on point for what
we're trying to explain there, and could easily make the text less
comprehensible not more so.

A simple "fix" would be to remove the claim about "," and just compare
CROSS JOIN to INNER JOIN ON TRUE. I'm not really convinced that's an
improvement ...

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David G Johnston 2014-11-18 17:42:39 Re: BUG #12000: "CROSS JOIN" not equivalent to ","
Previous Message kunert 2014-11-18 17:11:26 BUG #12000: "CROSS JOIN" not equivalent to ","