From 091fe037757abbecd6994daea0ae4eaa87f7217e Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 3 Sep 2006 22:37:06 +0000 Subject: Code review for UPDATE SET (columnlist) patch. Make it handle as much of the syntax as this fundamentally dead-end approach can, in particular combinations of single and multi column assignments. Improve rather inadequate documentation and provide some regression tests. --- doc/src/sgml/ref/update.sgml | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'doc/src') 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 @@ @@ -21,8 +21,8 @@ PostgreSQL documentation UPDATE [ ONLY ] table [ [ AS ] alias ] - [ SET column = { expression | DEFAULT } [, ...] | - SET ( column [, ...] ) = ( { expression | DEFAULT } [, ...] ) [, ...] ] + SET { column = { expression | DEFAULT } | + ( column [, ...] ) = ( { expression | DEFAULT } [, ...] ) } [, ...] [ FROM fromlist ] [ WHERE condition ] [ RETURNING * | output_expression [ AS output_name ] [, ...] ] @@ -251,10 +251,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'; - - -UPDATE weather SET (temp_lo, temp_hi, prcp) = (temp_lo+1, temp_lo+15, DEFAULT) - WHERE city = 'San Francisco' AND date = '2003-07-03'; @@ -268,6 +264,14 @@ UPDATE weather SET temp_lo = temp_lo+1, temp_hi = temp_lo+15, prcp = DEFAULT + + Use the alternative column-list syntax to do the same update: + +UPDATE weather SET (temp_lo, temp_hi, prcp) = (temp_lo+1, temp_lo+15, DEFAULT) + WHERE city = 'San Francisco' AND date = '2003-07-03'; + + + Increment the sales count of the salesperson who manages the account for Acme Corporation, using the FROM @@ -316,6 +320,19 @@ COMMIT; are PostgreSQL extensions. + + 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: + +UPDATE accounts SET (contact_last_name, contact_first_name) = + (SELECT last_name, first_name FROM salesmen + WHERE salesmen.id = accounts.sales_id); + + This is not currently implemented — the source must be a list + of independent expressions. + + Some other database systems offer a FROM option in which the target table is supposed to be listed again within FROM. -- cgit v1.2.3