diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2014-06-18 13:22:25 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2014-06-18 13:22:34 -0400 |
commit | 8f889b1083f38f4f5b3bd3512008a3f60e939244 (patch) | |
tree | 68c2e242c88245ea0d3b9329e1e27c78a8e70eaf /src/backend/nodes/copyfuncs.c | |
parent | 230ba02d855de7fac31bfb6af25ebd4ae052640b (diff) | |
download | postgresql-8f889b1083f38f4f5b3bd3512008a3f60e939244.tar.gz postgresql-8f889b1083f38f4f5b3bd3512008a3f60e939244.zip |
Implement UPDATE tab SET (col1,col2,...) = (SELECT ...), ...
This SQL-standard feature allows a sub-SELECT yielding multiple columns
(but only one row) to be used to compute the new values of several columns
to be updated. While the same results can be had with an independent
sub-SELECT per column, such a workaround can require a great deal of
duplicated computation.
The standard actually says that the source for a multi-column assignment
could be any row-valued expression. The implementation used here is
tightly tied to our existing sub-SELECT support and can't handle other
cases; the Bison grammar would have some issues with them too. However,
I don't feel too bad about this since other cases can be converted into
sub-SELECTs. For instance, "SET (a,b,c) = row_valued_function(x)" could
be written "SET (a,b,c) = (SELECT * FROM row_valued_function(x))".
Diffstat (limited to 'src/backend/nodes/copyfuncs.c')
-rw-r--r-- | src/backend/nodes/copyfuncs.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 43530aa24a8..8d3d5a7c734 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -1327,6 +1327,7 @@ _copySubLink(const SubLink *from) SubLink *newnode = makeNode(SubLink); COPY_SCALAR_FIELD(subLinkType); + COPY_SCALAR_FIELD(subLinkId); COPY_NODE_FIELD(testexpr); COPY_NODE_FIELD(operName); COPY_NODE_FIELD(subselect); @@ -2247,6 +2248,18 @@ _copyResTarget(const ResTarget *from) return newnode; } +static MultiAssignRef * +_copyMultiAssignRef(const MultiAssignRef *from) +{ + MultiAssignRef *newnode = makeNode(MultiAssignRef); + + COPY_NODE_FIELD(source); + COPY_SCALAR_FIELD(colno); + COPY_SCALAR_FIELD(ncolumns); + + return newnode; +} + static TypeName * _copyTypeName(const TypeName *from) { @@ -4561,6 +4574,9 @@ copyObject(const void *from) case T_ResTarget: retval = _copyResTarget(from); break; + case T_MultiAssignRef: + retval = _copyMultiAssignRef(from); + break; case T_TypeCast: retval = _copyTypeCast(from); break; |