SELECT documentation - Mailing list pgsql-hackers

From Joel Jacobson
Subject SELECT documentation
Date
Msg-id 67b71d3e-0c22-44df-a223-351f14418319@www.fastmail.com
Whole thread Raw
Responses Re: SELECT documentation
List pgsql-hackers
Hi,

The Examples section in the documentation for the SELECT command [1]
only contains a single example on how to join two tables,
which is written in SQL-89 style:

SELECT f.title, f.did, d.name, f.date_prod, f.kind
    FROM distributors d, films f
    WHERE f.did = d.did

I think it's good to keep this example query as it is,
and suggest we add the following equivalent queries:

SELECT f.title, f.did, d.name, f.date_prod, f.kind
    FROM distributors d
    JOIN films f ON f.did = d.did

SELECT f.title, f.did, d.name, f.date_prod, f.kind
    FROM distributors d
    JOIN films f USING (did)

SELECT f.title, f.did, d.name, f.date_prod, f.kind
    FROM distributors d
    NATURAL JOIN films f

I also think it would be an improvement to break up the from_item below into three separate items,
since the optional NATURAL cannot occur in combination with ON nor USING.
 
    from_item [ NATURAL ] join_type from_item [ ON join_condition | USING ( join_column [, ...] ) [ AS join_using_alias ] ]

Suggestion:

    from_item join_type from_item ON join_condition
    from_item join_type from_item USING ( join_column [, ...] ) [ AS join_using_alias ]
    from_item NATURAL join_type from_item
 
This would be more readable imo.
I picked the order ON, USING, NATURAL to match the order they are described in the FROM Clause section.

/Joel

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Strange path from pgarch_readyXlog()
Next
From: Zhihong Yu
Date:
Subject: Re: UNIQUE null treatment option