1
1
<!--
2
- $Header: /cvsroot/pgsql/doc/src/sgml/ref/select.sgml,v 1.57 2002/08/28 14:35:37 momjian Exp $
2
+ $Header: /cvsroot/pgsql/doc/src/sgml/ref/select.sgml,v 1.58 2002/08/29 00:17:01 tgl Exp $
3
3
PostgreSQL documentation
4
4
-->
5
5
@@ -40,10 +40,10 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be:
40
40
( <replaceable class="PARAMETER">select</replaceable> )
41
41
[ AS ] <replaceable class="PARAMETER">alias</replaceable> [ ( <replaceable class="PARAMETER">column_alias_list</replaceable> ) ]
42
42
|
43
- <replaceable class="PARAMETER">table_function_name</replaceable> ( [ <replaceable class="parameter">argtype </replaceable> [, ...] ] )
43
+ <replaceable class="PARAMETER">table_function_name</replaceable> ( [ <replaceable class="parameter">argument </replaceable> [, ...] ] )
44
44
[ AS ] <replaceable class="PARAMETER">alias</replaceable> [ ( <replaceable class="PARAMETER">column_alias_list</replaceable> | <replaceable class="PARAMETER">column_definition_list</replaceable> ) ]
45
45
|
46
- <replaceable class="PARAMETER">table_function_name</replaceable> ( [ <replaceable class="parameter">argtype </replaceable> [, ...] ] )
46
+ <replaceable class="PARAMETER">table_function_name</replaceable> ( [ <replaceable class="parameter">argument </replaceable> [, ...] ] )
47
47
AS ( <replaceable class="PARAMETER">column_definition_list</replaceable> )
48
48
|
49
49
<replaceable class="PARAMETER">from_item</replaceable> [ NATURAL ] <replaceable class="PARAMETER">join_type</replaceable> <replaceable class="PARAMETER">from_item</replaceable>
@@ -142,10 +142,14 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be:
142
142
<term><replaceable class="PARAMETER">alias</replaceable></term>
143
143
<listitem>
144
144
<para>
145
- A substitute name for the preceding
146
- <replaceable class="PARAMETER">table_name</replaceable>.
145
+ A substitute name for the FROM item containing the alias.
147
146
An alias is used for brevity or to eliminate ambiguity for self-joins
148
- (where the same table is scanned multiple times). If an alias is
147
+ (where the same table is scanned multiple times). When an alias
148
+ is provided, it completely hides the actual name of the table or
149
+ table function; for example given <literal>FROM foo AS f</>, the
150
+ remainder of the SELECT must refer to this FROM item as <literal>f</>
151
+ not <literal>foo</>.
152
+ If an alias is
149
153
written, a column alias list can also be written to provide
150
154
substitute names for one or more columns of the table.
151
155
</para>
@@ -172,12 +176,15 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be:
172
176
A table function can appear in the FROM clause. This acts as though
173
177
its output were created as a temporary table for the duration of
174
178
this single SELECT command. An alias may also be used. If an alias is
175
- written, a column alias list can also be written to provide substitute names
176
- for one or more columns of the table function. If the table function has been
177
- defined as returning the RECORD data type, an alias, or the keyword AS, must
178
- also be present, followed by a column definition list in the form
179
- ( <replaceable class="PARAMETER">column_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [, ... ] ).
180
- The column definition list must match the actual number and types returned by the function.
179
+ written, a column alias list can also be written to provide substitute
180
+ names for one or more columns of the table function. If the table
181
+ function has been defined as returning the <type>record</> data type,
182
+ an alias, or the keyword <literal>AS</>, must be present, followed by
183
+ a column definition list in the form ( <replaceable
184
+ class="PARAMETER">column_name</replaceable> <replaceable
185
+ class="PARAMETER">data_type</replaceable> [, ... ] ).
186
+ The column definition list must match the actual number and types
187
+ of columns returned by the function.
181
188
</para>
182
189
</listitem>
183
190
</varlistentry>
@@ -395,7 +402,7 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be:
395
402
this was the default result, and adding sub-tables was done
396
403
by appending <command>*</command> to the table name.
397
404
This old behavior is available via the command
398
- <command>SET SQL_Inheritance TO OFF; </command>
405
+ <command>SET SQL_Inheritance TO OFF</command>.
399
406
</para>
400
407
401
408
<para>
@@ -406,16 +413,22 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be:
406
413
</para>
407
414
408
415
<para>
409
- A FROM item can be a table function (i.e. a function that returns
410
- multiple rows and columns). When a table function is created, it may
411
- be defined to return a named scalar or composite data type (an existing
412
- scalar data type, or a table or view name), or it may be defined to return
413
- a RECORD data type. When a table function is defined to return RECORD, it
414
- must be followed in the FROM clause by an alias, or the keyword AS alone,
415
- and then by a parenthesized list of column names and types. This provides
416
- a query-time composite type definition. The FROM clause composite type
417
- must match the actual composite type returned from the function or an
418
- ERROR will be generated.
416
+ A FROM item can be a table function (typically, a function that returns
417
+ multiple rows and/or columns, though actually any function can be used).
418
+ The function is invoked with the given argument value(s), and then its
419
+ output is scanned as though it were a table.
420
+ </para>
421
+
422
+ <para>
423
+ In some cases it is useful to define table functions that can return
424
+ different column sets depending on how they are invoked. To support this,
425
+ the table function can be declared as returning the pseudo-type
426
+ <type>record</>. When such a function is used in FROM, it must be
427
+ followed by an alias, or the keyword <literal>AS</> alone,
428
+ and then by a parenthesized list of column names and types. This provides
429
+ a query-time composite type definition. The composite type definition
430
+ must match the actual composite type returned from the function, or an
431
+ error will be reported at run-time.
419
432
</para>
420
433
421
434
<para>
@@ -827,6 +840,38 @@ SELECT name FROM distributors ORDER BY code;
827
840
unless ORDER BY is used to constrain the order.
828
841
</para>
829
842
</refsect2>
843
+
844
+ <refsect2 id="SQL-FOR-UPDATE">
845
+ <refsect2info>
846
+ <date>2002-08-28</date>
847
+ </refsect2info>
848
+ <title id="sql-for-update-title">
849
+ FOR UPDATE Clause
850
+ </title>
851
+ <para>
852
+ <synopsis>
853
+ FOR UPDATE [ OF <replaceable class="PARAMETER">tablename</replaceable> [, ...] ]
854
+ </synopsis>
855
+ </para>
856
+
857
+ <para>
858
+ FOR UPDATE causes the rows retrieved by the query to be locked as though
859
+ for update. This prevents them from being modified or deleted by other
860
+ transactions until the current transaction ends.
861
+ </para>
862
+
863
+ <para>
864
+ If specific tables are named in FOR UPDATE, then only rows coming from
865
+ those tables are locked.
866
+ </para>
867
+
868
+ <para>
869
+ FOR UPDATE cannot be used in contexts where returned rows can't be clearly
870
+ identified with individual table rows; for example it can't be used with
871
+ aggregation.
872
+ </para>
873
+ </refsect2>
874
+
830
875
</refsect1>
831
876
832
877
<refsect1 id="R1-SQL-SELECT-2">
@@ -1019,8 +1064,7 @@ SELECT * FROM distributors_2(111) AS (f1 int, f2 text);
1019
1064
<productname>PostgreSQL</productname> allows one to omit
1020
1065
the <command>FROM</command> clause from a query. This feature
1021
1066
was retained from the original PostQuel query language. It has
1022
- a straightforward use to compute the results of simple constant
1023
- expressions:
1067
+ a straightforward use to compute the results of simple expressions:
1024
1068
1025
1069
<programlisting>
1026
1070
SELECT 2+2;
@@ -1062,6 +1106,11 @@ and later will warn if the implicit-FROM feature is used in a query that also
1062
1106
contains an explicit FROM clause.
1063
1107
1064
1108
</para>
1109
+
1110
+ <para>
1111
+ The table-function feature is a <productname>PostgreSQL</productname>
1112
+ extension.
1113
+ </para>
1065
1114
</refsect2>
1066
1115
1067
1116
<refsect2 id="R2-SQL-SELECT-5">
0 commit comments