summaryrefslogtreecommitdiff
path: root/doc/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-11-22 15:19:57 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2016-11-22 15:20:10 -0500
commit906bfcad7ba7cb3863fe0e2a7810be8e3cd84fbd (patch)
treecfed5faaab5c2de39eedf658b804df67ad8c08aa /doc/src
parente8ac886c24776295dd9b025386a821061da8e4d1 (diff)
Improve handling of "UPDATE ... SET (column_list) = row_constructor".
Previously, the right-hand side of a multiple-column assignment, if it wasn't a sub-SELECT, had to be a simple parenthesized expression list, because gram.y was responsible for "bursting" the construct into independent column assignments. This had the minor defect that you couldn't write ROW (though you should be able to, since the standard says this is a row constructor), and the rather larger defect that unlike other uses of row constructors, we would not expand a "foo.*" item into multiple columns. Fix that by changing the RHS to be just "a_expr" in the grammar, leaving it to transformMultiAssignRef to separate the elements of a RowExpr; which it will do only after performing standard transformation of the RowExpr, so that "foo.*" behaves as expected. The key reason we didn't do that before was the hard-wired handling of DEFAULT tokens (SetToDefault nodes). This patch deals with that issue by allowing DEFAULT in any a_expr and having parse analysis throw an error if SetToDefault is found in an unexpected place. That's an improvement anyway since the error can be more specific than just "syntax error". The SQL standard suggests that the RHS could be any a_expr yielding a suitable row value. This patch doesn't really move the goal posts in that respect --- you're still limited to RowExpr or a sub-SELECT --- but it does fix the grammar restriction, so it provides some tangible progress towards a full implementation. And the limitation is now documented by an explicit error message rather than an unhelpful "syntax error". Discussion: <8542.1479742008@sss.pgh.pa.us>
Diffstat (limited to 'doc/src')
-rw-r--r--doc/src/sgml/ref/update.sgml14
1 files changed, 7 insertions, 7 deletions
diff --git a/doc/src/sgml/ref/update.sgml b/doc/src/sgml/ref/update.sgml
index c50434f85f9..2de0f4aad10 100644
--- a/doc/src/sgml/ref/update.sgml
+++ b/doc/src/sgml/ref/update.sgml
@@ -24,7 +24,7 @@ PostgreSQL documentation
[ WITH [ RECURSIVE ] <replaceable class="parameter">with_query</replaceable> [, ...] ]
UPDATE [ ONLY ] <replaceable class="PARAMETER">table_name</replaceable> [ * ] [ [ AS ] <replaceable class="parameter">alias</replaceable> ]
SET { <replaceable class="PARAMETER">column_name</replaceable> = { <replaceable class="PARAMETER">expression</replaceable> | DEFAULT } |
- ( <replaceable class="PARAMETER">column_name</replaceable> [, ...] ) = ( { <replaceable class="PARAMETER">expression</replaceable> | DEFAULT } [, ...] ) |
+ ( <replaceable class="PARAMETER">column_name</replaceable> [, ...] ) = [ ROW ] ( { <replaceable class="PARAMETER">expression</replaceable> | DEFAULT } [, ...] ) |
( <replaceable class="PARAMETER">column_name</replaceable> [, ...] ) = ( <replaceable class="PARAMETER">sub-SELECT</replaceable> )
} [, ...]
[ FROM <replaceable class="PARAMETER">from_list</replaceable> ]
@@ -420,12 +420,12 @@ UPDATE films SET kind = 'Dramatic' WHERE CURRENT OF c_films;
<para>
According to the standard, the source value for a parenthesized sub-list of
- column names can be any row-valued expression yielding the correct number
- of columns. <productname>PostgreSQL</productname> only allows the source
- value to be a parenthesized list of expressions (a row constructor) or a
- sub-<literal>SELECT</>. An individual column's updated value can be
- specified as <literal>DEFAULT</> in the row-constructor case, but not
- inside a sub-<literal>SELECT</>.
+ target column names can be any row-valued expression yielding the correct
+ number of columns. <productname>PostgreSQL</productname> only allows the
+ source value to be a <link linkend="sql-syntax-row-constructors">row
+ constructor</link> or a sub-<literal>SELECT</>. An individual column's
+ updated value can be specified as <literal>DEFAULT</> in the
+ row-constructor case, but not inside a sub-<literal>SELECT</>.
</para>
</refsect1>
</refentry>