1
1
<!--
2
- $Header: /cvsroot/pgsql/doc/src/sgml/ref/select.sgml,v 1.71 2003/11/01 01:56:29 petere Exp $
2
+ $Header: /cvsroot/pgsql/doc/src/sgml/ref/select.sgml,v 1.72 2003/11/04 00:34:45 tgl Exp $
3
3
PostgreSQL documentation
4
4
-->
5
5
@@ -41,11 +41,6 @@ where <replaceable class="parameter">from_item</replaceable> can be one of:
41
41
<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> [, ...] ) ]
42
42
</synopsis>
43
43
44
- <comment>FIXME: This last syntax is incorrect if the join type is an
45
- INNER or OUTER join (in which case one of NATURAL, ON ..., or USING
46
- ... is mandatory, not optional). What's the best way to fix
47
- this?</comment>
48
-
49
44
</refsynopsisdiv>
50
45
51
46
<refsect1>
@@ -107,7 +102,7 @@ this?</comment>
107
102
108
103
<listitem>
109
104
<para>
110
- The actual output rows are computed the
105
+ The actual output rows are computed using the
111
106
<command>SELECT</command> output expressions for each selected
112
107
row. (See
113
108
<xref linkend="sql-select-list" endterm="sql-select-list-title">
@@ -125,15 +120,6 @@ this?</comment>
125
120
</para>
126
121
</listitem>
127
122
128
- <listitem>
129
- <para>
130
- If the <literal>LIMIT</literal> or <literal>OFFSET</literal>
131
- clause is specified, the <command>SELECT</command> statement
132
- only returns a subset of the result rows. (See <xref
133
- linkend="sql-limit" endterm="sql-limit-title"> below.)
134
- </para>
135
- </listitem>
136
-
137
123
<listitem>
138
124
<para>
139
125
<literal>DISTINCT</literal> eliminates duplicate rows from the
@@ -145,6 +131,15 @@ this?</comment>
145
131
</para>
146
132
</listitem>
147
133
134
+ <listitem>
135
+ <para>
136
+ If the <literal>LIMIT</literal> or <literal>OFFSET</literal>
137
+ clause is specified, the <command>SELECT</command> statement
138
+ only returns a subset of the result rows. (See <xref
139
+ linkend="sql-limit" endterm="sql-limit-title"> below.)
140
+ </para>
141
+ </listitem>
142
+
148
143
<listitem>
149
144
<para>
150
145
The <literal>FOR UPDATE</literal> clause causes the
@@ -291,17 +286,21 @@ this?</comment>
291
286
</para>
292
287
293
288
<para>
294
- A <literal>JOIN</literal> clause, combines two
295
- <literal>FROM</> items. (Use parentheses if necessary to
296
- determine the order of nesting.)
289
+ A <literal>JOIN</literal> clause combines two
290
+ <literal>FROM</> items. Use parentheses if necessary to
291
+ determine the order of nesting. In the absence of parentheses,
292
+ <literal>JOIN</literal>s nest left-to-right. In any case
293
+ <literal>JOIN</literal> binds more tightly than the commas
294
+ separating <literal>FROM</> items.
297
295
</para>
298
296
299
297
<para>
300
298
<literal>CROSS JOIN</> and <literal>INNER JOIN</literal>
301
- produce a simple Cartesian product, the same as you get from
302
- listing the two items at the top level of <literal>FROM</>.
299
+ produce a simple Cartesian product, the same result as you get from
300
+ listing the two items at the top level of <literal>FROM</>,
301
+ but restricted by the join condition (if any).
303
302
<literal>CROSS JOIN</> is equivalent to <literal>INNER JOIN ON
304
- (true )</>, that is, no rows are removed by qualification.
303
+ (TRUE )</>, that is, no rows are removed by qualification.
305
304
These join types are just a notational convenience, since they
306
305
do nothing you couldn't do with plain <literal>FROM</> and
307
306
<literal>WHERE</>.
@@ -315,7 +314,7 @@ this?</comment>
315
314
condition. This left-hand row is extended to the full width
316
315
of the joined table by inserting null values for the
317
316
right-hand columns. Note that only the <literal>JOIN</>
318
- clauses own condition is considered while deciding which rows
317
+ clause's own condition is considered while deciding which rows
319
318
have matches. Outer conditions are applied afterwards.
320
319
</para>
321
320
@@ -410,7 +409,7 @@ GROUP BY <replaceable class="parameter">expression</replaceable> [, ...]
410
409
expressions. <replaceable
411
410
class="parameter">expression</replaceable> can be an input column
412
411
name, or the name or ordinal number of an output column
413
- (<command>SELECT</command> list), or it can be an arbitrary
412
+ (<command>SELECT</command> list item ), or an arbitrary
414
413
expression formed from input-column values. In case of ambiguity,
415
414
a <literal>GROUP BY</literal> name will be interpreted as an
416
415
input-column name rather than an output column name.
@@ -497,7 +496,7 @@ HAVING <replaceable class="parameter">condition</replaceable>
497
496
498
497
<para>
499
498
Currently, <literal>FOR UPDATE</> may not be specified either for
500
- a <literal>UNION</> result or for the inputs of <literal>UNION</>.
499
+ a <literal>UNION</> result or for any input of a <literal>UNION</>.
501
500
</para>
502
501
</refsect2>
503
502
@@ -613,7 +612,7 @@ ORDER BY <replaceable class="parameter">expression</replaceable> [ ASC | DESC |
613
612
</synopsis>
614
613
<replaceable class="parameter">expression</replaceable> can be the
615
614
name or ordinal number of an output column
616
- (<command>SELECT</command> list), or it can be an arbitrary
615
+ (<command>SELECT</command> list item ), or it can be an arbitrary
617
616
expression formed from input-column values.
618
617
</para>
619
618
@@ -623,7 +622,7 @@ ORDER BY <replaceable class="parameter">expression</replaceable> [ ASC | DESC |
623
622
equal according to the leftmost expression, the are compared
624
623
according to the next expression and so on. If they are equal
625
624
according to all specified expressions, they are returned in
626
- random order.
625
+ an implementation-dependent order.
627
626
</para>
628
627
629
628
<para>
@@ -660,7 +659,7 @@ SELECT name FROM distributors ORDER BY code;
660
659
661
660
<para>
662
661
Optionally one may add the key word <literal>ASC</> (ascending) or
663
- <literal>DESC</> (descending) after each expression in the
662
+ <literal>DESC</> (descending) after any expression in the
664
663
<literal>ORDER BY</> clause. If not specified, <literal>ASC</> is
665
664
assumed by default. Alternatively, a specific ordering operator
666
665
name may be specified in the <literal>USING</> clause.
@@ -689,15 +688,18 @@ SELECT name FROM distributors ORDER BY code;
689
688
690
689
<para>
691
690
The <literal>LIMIT</literal> clause consists of two independent
692
- clauses:
691
+ sub- clauses:
693
692
<synopsis>
694
693
LIMIT { <replaceable class="parameter">count</replaceable> | ALL }
695
694
OFFSET <replaceable class="parameter">start</replaceable>
696
695
</synopsis>
697
696
<replaceable class="parameter">count</replaceable> specifies the
698
- maximum number of rows to return, and <replaceable
697
+ maximum number of rows to return, while <replaceable
699
698
class="parameter">start</replaceable> specifies the number of rows
700
- to skip before starting to return rows.
699
+ to skip before starting to return rows. When both are specified,
700
+ <replaceable class="parameter">start</replaceable> rows are skipped
701
+ before starting to count the <replaceable
702
+ class="parameter">count</replaceable> rows to be returned.
701
703
</para>
702
704
703
705
<para>
@@ -754,6 +756,13 @@ SELECT DISTINCT ON (location) location, time, report
754
756
of time values for each location, we'd have gotten a report from
755
757
an unpredictable time for each location.
756
758
</para>
759
+
760
+ <para>
761
+ The <literal>DISTINCT ON</> expression(s) must match the leftmost
762
+ <literal>ORDER BY</> expression(s). The <literal>ORDER BY</> clause
763
+ will normally contain additional expression(s) that determine the
764
+ desired precedence of rows within each <literal>DISTINCT ON</> group.
765
+ </para>
757
766
</refsect2>
758
767
759
768
<refsect2 id="SQL-FOR-UPDATE">
@@ -889,10 +898,10 @@ SELECT * FROM distributors ORDER BY 2;
889
898
</para>
890
899
891
900
<para>
892
- This example shows how to obtain the union of the tables
901
+ The next example shows how to obtain the union of the tables
893
902
<literal>distributors</literal> and
894
903
<literal>actors</literal>, restricting the results to those that begin
895
- with letter W in each table. Only distinct rows are wanted, so the
904
+ with the letter W in each table. Only distinct rows are wanted, so the
896
905
key word <literal>ALL</literal> is omitted.
897
906
898
907
<programlisting>
@@ -925,7 +934,7 @@ SELECT actors.name
925
934
926
935
<para>
927
936
This example shows how to use a function in the <literal>FROM</>
928
- clause, both with and without a column definition list.
937
+ clause, both with and without a column definition list:
929
938
930
939
<programlisting>
931
940
CREATE FUNCTION distributors(int) RETURNS SETOF distributors AS '
@@ -1048,7 +1057,8 @@ SELECT distributors.* FROM distributors d, distributors distributors;
1048
1057
</para>
1049
1058
1050
1059
<para>
1051
- SQL99 uses a slightly different definition which is not upward compatible
1060
+ SQL99 uses a slightly different definition which is not entirely upward
1061
+ compatible
1052
1062
with SQL92. In most cases, however, <productname>PostgreSQL</productname>
1053
1063
will interpret an <literal>ORDER BY</literal> or <literal>GROUP
1054
1064
BY</literal> expression the same way SQL99 does.
0 commit comments