11<!--
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 $
33PostgreSQL documentation
44-->
55
@@ -40,10 +40,10 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be:
4040( <replaceable class="PARAMETER">select</replaceable> )
4141 [ AS ] <replaceable class="PARAMETER">alias</replaceable> [ ( <replaceable class="PARAMETER">column_alias_list</replaceable> ) ]
4242|
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> [, ...] ] )
4444 [ AS ] <replaceable class="PARAMETER">alias</replaceable> [ ( <replaceable class="PARAMETER">column_alias_list</replaceable> | <replaceable class="PARAMETER">column_definition_list</replaceable> ) ]
4545|
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> [, ...] ] )
4747 AS ( <replaceable class="PARAMETER">column_definition_list</replaceable> )
4848|
4949<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:
142142 <term><replaceable class="PARAMETER">alias</replaceable></term>
143143 <listitem>
144144 <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.
147146An 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
149153written, a column alias list can also be written to provide
150154substitute names for one or more columns of the table.
151155 </para>
@@ -172,12 +176,15 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be:
172176A table function can appear in the FROM clause. This acts as though
173177its output were created as a temporary table for the duration of
174178this single SELECT command. An alias may also be used. If an alias is
175- written, a column alias list can also be written to providesubstitute 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.
181188 </para>
182189 </listitem>
183190 </varlistentry>
@@ -395,7 +402,7 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be:
395402 this was the default result, and adding sub-tables was done
396403 by appending <command>*</command> to the table name.
397404 This old behavior is available via the command
398- <command>SET SQL_Inheritance TO OFF; </command>
405+ <command>SET SQL_Inheritance TO OFF</command>.
399406 </para>
400407
401408 <para>
@@ -406,16 +413,22 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be:
406413 </para>
407414
408415 <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.
419432 </para>
420433
421434 <para>
@@ -827,6 +840,38 @@ SELECT name FROM distributors ORDER BY code;
827840 unless ORDER BY is used to constrain the order.
828841 </para>
829842 </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+
830875 </refsect1>
831876
832877 <refsect1 id="R1-SQL-SELECT-2">
@@ -1019,8 +1064,7 @@ SELECT * FROM distributors_2(111) AS (f1 int, f2 text);
10191064<productname>PostgreSQL</productname> allows one to omit
10201065the <command>FROM</command> clause from a query. This feature
10211066was 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:
10241068
10251069 <programlisting>
10261070SELECT 2+2;
@@ -1062,6 +1106,11 @@ and later will warn if the implicit-FROM feature is used in a query that also
10621106contains an explicit FROM clause.
10631107
10641108 </para>
1109+
1110+ <para>
1111+ The table-function feature is a <productname>PostgreSQL</productname>
1112+ extension.
1113+ </para>
10651114 </refsect2>
10661115
10671116 <refsect2 id="R2-SQL-SELECT-5">