diff options
Diffstat (limited to 'doc/src/sgml/ref/update.sgml')
-rw-r--r-- | doc/src/sgml/ref/update.sgml | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/doc/src/sgml/ref/update.sgml b/doc/src/sgml/ref/update.sgml index 7b5d17a1fc8..ec2200f3bc9 100644 --- a/doc/src/sgml/ref/update.sgml +++ b/doc/src/sgml/ref/update.sgml @@ -1,5 +1,5 @@ <!-- -$PostgreSQL: pgsql/doc/src/sgml/ref/update.sgml,v 1.39 2006/09/02 20:34:47 momjian Exp $ +$PostgreSQL: pgsql/doc/src/sgml/ref/update.sgml,v 1.40 2006/09/03 22:37:05 tgl Exp $ PostgreSQL documentation --> @@ -21,8 +21,8 @@ PostgreSQL documentation <refsynopsisdiv> <synopsis> UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> [ [ AS ] <replaceable class="parameter">alias</replaceable> ] - [ SET <replaceable class="PARAMETER">column</replaceable> = { <replaceable class="PARAMETER">expression</replaceable> | DEFAULT } [, ...] | - SET ( <replaceable class="PARAMETER">column</replaceable> [, ...] ) = ( { <replaceable class="PARAMETER">expression</replaceable> | DEFAULT } [, ...] ) [, ...] ] + SET { <replaceable class="PARAMETER">column</replaceable> = { <replaceable class="PARAMETER">expression</replaceable> | DEFAULT } | + ( <replaceable class="PARAMETER">column</replaceable> [, ...] ) = ( { <replaceable class="PARAMETER">expression</replaceable> | DEFAULT } [, ...] ) } [, ...] [ FROM <replaceable class="PARAMETER">fromlist</replaceable> ] [ WHERE <replaceable class="PARAMETER">condition</replaceable> ] [ RETURNING * | <replaceable class="parameter">output_expression</replaceable> [ AS <replaceable class="parameter">output_name</replaceable> ] [, ...] ] @@ -252,10 +252,6 @@ UPDATE films SET kind = 'Dramatic' WHERE kind = 'Drama'; UPDATE weather SET temp_lo = temp_lo+1, temp_hi = temp_lo+15, prcp = DEFAULT WHERE city = 'San Francisco' AND date = '2003-07-03'; </programlisting> -<programlisting> -UPDATE weather SET (temp_lo, temp_hi, prcp) = (temp_lo+1, temp_lo+15, DEFAULT) - WHERE city = 'San Francisco' AND date = '2003-07-03'; -</programlisting> </para> <para> @@ -269,6 +265,14 @@ UPDATE weather SET temp_lo = temp_lo+1, temp_hi = temp_lo+15, prcp = DEFAULT </para> <para> + Use the alternative column-list syntax to do the same update: +<programlisting> +UPDATE weather SET (temp_lo, temp_hi, prcp) = (temp_lo+1, temp_lo+15, DEFAULT) + WHERE city = 'San Francisco' AND date = '2003-07-03'; +</programlisting> + </para> + + <para> Increment the sales count of the salesperson who manages the account for Acme Corporation, using the <literal>FROM</literal> clause syntax: @@ -317,6 +321,19 @@ COMMIT; </para> <para> + According to the standard, the column-list syntax should allow a list + of columns to be assigned from a single row-valued expression, such + as a sub-select: +<programlisting> +UPDATE accounts SET (contact_last_name, contact_first_name) = + (SELECT last_name, first_name FROM salesmen + WHERE salesmen.id = accounts.sales_id); +</programlisting> + This is not currently implemented — the source must be a list + of independent expressions. + </para> + + <para> Some other database systems offer a <literal>FROM</> option in which the target table is supposed to be listed again within <literal>FROM</>. That is not how <productname>PostgreSQL</productname> interprets |