Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 181cc09

Browse files
committed
doc: split out the NATURAL/CROSS JOIN in SELECT syntax
This allows the syntax to be more accurate about what clauses are supported. Also switch an example query to use the ANSI join syntax. Reported-by: Joel Jacobson Discussion: https://postgr.es/m/67b71d3e-0c22-44df-a223-351f14418319@www.fastmail.com Backpatch-through: 11
1 parent b6fe152 commit 181cc09

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

doc/src/sgml/ref/select.sgml

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ SELECT [ ALL | DISTINCT [ ON ( <replaceable class="parameter">expression</replac
5959
[ LATERAL ] <replaceable class="parameter">function_name</replaceable> ( [ <replaceable class="parameter">argument</replaceable> [, ...] ] ) AS ( <replaceable class="parameter">column_definition</replaceable> [, ...] )
6060
[ LATERAL ] ROWS FROM( <replaceable class="parameter">function_name</replaceable> ( [ <replaceable class="parameter">argument</replaceable> [, ...] ] ) [ AS ( <replaceable class="parameter">column_definition</replaceable> [, ...] ) ] [, ...] )
6161
[ WITH ORDINALITY ] [ [ AS ] <replaceable class="parameter">alias</replaceable> [ ( <replaceable class="parameter">column_alias</replaceable> [, ...] ) ] ]
62-
<replaceable class="parameter">from_item</replaceable> [ NATURAL ] <replaceable class="parameter">join_type</replaceable> <replaceable class="parameter">from_item</replaceable> [ ON <replaceable class="parameter">join_condition</replaceable> | USING ( <replaceable class="parameter">join_column</replaceable> [, ...] ) ]
62+
<replaceable class="parameter">from_item</replaceable> <replaceable class="parameter">join_type</replaceable> <replaceable class="parameter">from_item</replaceable> { ON <replaceable class="parameter">join_condition</replaceable> | USING ( <replaceable class="parameter">join_column</replaceable> [, ...] ) }
63+
<replaceable class="parameter">from_item</replaceable> NATURAL <replaceable class="parameter">join_type</replaceable> <replaceable class="parameter">from_item</replaceable>
64+
<replaceable class="parameter">from_item</replaceable> CROSS JOIN <replaceable class="parameter">from_item</replaceable>
6365

6466
<phrase>and <replaceable class="parameter">grouping_element</replaceable> can be one of:</phrase>
6567

@@ -554,19 +556,15 @@ TABLE [ ONLY ] <replaceable class="parameter">table_name</replaceable> [ * ]
554556
<listitem>
555557
<para><literal>FULL [ OUTER ] JOIN</literal></para>
556558
</listitem>
557-
<listitem>
558-
<para><literal>CROSS JOIN</literal></para>
559-
</listitem>
560559
</itemizedlist>
561560

562561
For the <literal>INNER</literal> and <literal>OUTER</literal> join types, a
563562
join condition must be specified, namely exactly one of
564-
<literal>NATURAL</literal>, <literal>ON <replaceable
565-
class="parameter">join_condition</replaceable></literal>, or
563+
<literal>ON <replaceable
564+
class="parameter">join_condition</replaceable></literal>,
566565
<literal>USING (<replaceable
567-
class="parameter">join_column</replaceable> [, ...])</literal>.
568-
See below for the meaning. For <literal>CROSS JOIN</literal>,
569-
none of these clauses can appear.
566+
class="parameter">join_column</replaceable> [, ...])</literal>,
567+
or <literal>NATURAL</literal>. See below for the meaning.
570568
</para>
571569

572570
<para>
@@ -577,17 +575,9 @@ TABLE [ ONLY ] <replaceable class="parameter">table_name</replaceable> [ * ]
577575
In the absence of parentheses, <literal>JOIN</literal>s nest
578576
left-to-right. In any case <literal>JOIN</literal> binds more
579577
tightly than the commas separating <literal>FROM</literal>-list items.
580-
</para>
581-
582-
<para><literal>CROSS JOIN</literal> and <literal>INNER JOIN</literal>
583-
produce a simple Cartesian product, the same result as you get from
584-
listing the two tables at the top level of <literal>FROM</literal>,
585-
but restricted by the join condition (if any).
586-
<literal>CROSS JOIN</literal> is equivalent to <literal>INNER JOIN ON
587-
(TRUE)</literal>, that is, no rows are removed by qualification.
588-
These join types are just a notational convenience, since they
589-
do nothing you couldn't do with plain <literal>FROM</literal> and
590-
<literal>WHERE</literal>.
578+
All the <literal>JOIN</literal> options are just a notational
579+
convenience, since they do nothing you couldn't do with plain
580+
<literal>FROM</literal> and <literal>WHERE</literal>.
591581
</para>
592582

593583
<para><literal>LEFT OUTER JOIN</literal> returns all rows in the qualified
@@ -656,6 +646,19 @@ TABLE [ ONLY ] <replaceable class="parameter">table_name</replaceable> [ * ]
656646
</listitem>
657647
</varlistentry>
658648

649+
<varlistentry>
650+
<term><literal>CROSS JOIN</literal></term>
651+
<listitem>
652+
<para>
653+
<literal>CROSS JOIN</literal> is equivalent to <literal>INNER JOIN ON
654+
(TRUE)</literal>, that is, no rows are removed by qualification.
655+
They produce a simple Cartesian product, the same result as you get from
656+
listing the two tables at the top level of <literal>FROM</literal>,
657+
but restricted by the join condition (if any).
658+
</para>
659+
</listitem>
660+
</varlistentry>
661+
659662
<varlistentry>
660663
<term><literal>LATERAL</literal></term>
661664
<listitem>
@@ -1693,8 +1696,7 @@ SELECT * FROM <replaceable class="parameter">name</replaceable>
16931696

16941697
<programlisting>
16951698
SELECT f.title, f.did, d.name, f.date_prod, f.kind
1696-
FROM distributors d, films f
1697-
WHERE f.did = d.did
1699+
FROM distributors d JOIN films f USING (did);
16981700

16991701
title | did | name | date_prod | kind
17001702
-------------------+-----+--------------+------------+----------

0 commit comments

Comments
 (0)