Re: Join condition parsing puzzle - Mailing list pgsql-general

From Tom Lane
Subject Re: Join condition parsing puzzle
Date
Msg-id 12727.1535061063@sss.pgh.pa.us
Whole thread Raw
In response to Join condition parsing puzzle  (Mark Jeffcoat <jeffcoat@alumni.rice.edu>)
Responses Re: Join condition parsing puzzle
List pgsql-general
Mark Jeffcoat <jeffcoat@alumni.rice.edu> writes:
> SELECT *
> FROM relation_a
> LEFT JOIN relation_b
> JOIN relation_c
> ON (relation_c.id_p = relation_b.id_p)
> ON (relation_a.id_c = relation_b.id_c AND relation_a.id_v = relation_b.id_v);

> I would have claimed before seeing this example that it wasn't even
> grammatical; I thought the only legal place to write the ON clause was
> immediately after the JOIN. Apparently not.

> How should I read this query?  I'd appreciate any help understanding this.

You read it as

SELECT *
FROM
  relation_a
  LEFT JOIN (relation_b
             JOIN relation_c
             ON (relation_c.id_p = relation_b.id_p))
  ON (relation_a.id_c = relation_b.id_c AND relation_a.id_v = relation_b.id_v);

There's no other valid way to parenthesize it, so that's what
the parser does.

            regards, tom lane


pgsql-general by date:

Previous
From: Nikolay Samokhvalov
Date:
Subject: Re: Upgrade/Downgrade
Next
From: Laurenz Albe
Date:
Subject: Re: Is my text_pattern_ops index working for a LIKE prefix searchwith column reference?