diff options
| author | Tom Lane | 2014-06-18 17:22:25 +0000 |
|---|---|---|
| committer | Tom Lane | 2014-06-18 17:22:34 +0000 |
| commit | 8f889b1083f38f4f5b3bd3512008a3f60e939244 (patch) | |
| tree | 68c2e242c88245ea0d3b9329e1e27c78a8e70eaf /src/backend/nodes/outfuncs.c | |
| parent | 230ba02d855de7fac31bfb6af25ebd4ae052640b (diff) | |
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/outfuncs.c')
| -rw-r--r-- | src/backend/nodes/outfuncs.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c index deff33f6f71..c182212e62f 100644 --- a/src/backend/nodes/outfuncs.c +++ b/src/backend/nodes/outfuncs.c @@ -1115,6 +1115,7 @@ _outSubLink(StringInfo str, const SubLink *node) WRITE_NODE_TYPE("SUBLINK"); WRITE_ENUM_FIELD(subLinkType, SubLinkType); + WRITE_INT_FIELD(subLinkId); WRITE_NODE_FIELD(testexpr); WRITE_NODE_FIELD(operName); WRITE_NODE_FIELD(subselect); @@ -1701,6 +1702,7 @@ _outPlannerInfo(StringInfo str, const PlannerInfo *node) WRITE_INT_FIELD(join_cur_level); WRITE_NODE_FIELD(init_plans); WRITE_NODE_FIELD(cte_plan_ids); + WRITE_NODE_FIELD(multiexpr_params); WRITE_NODE_FIELD(eq_classes); WRITE_NODE_FIELD(canon_pathkeys); WRITE_NODE_FIELD(left_join_clauses); @@ -2581,6 +2583,16 @@ _outResTarget(StringInfo str, const ResTarget *node) } static void +_outMultiAssignRef(StringInfo str, const MultiAssignRef *node) +{ + WRITE_NODE_TYPE("MULTIASSIGNREF"); + + WRITE_NODE_FIELD(source); + WRITE_INT_FIELD(colno); + WRITE_INT_FIELD(ncolumns); +} + +static void _outSortBy(StringInfo str, const SortBy *node) { WRITE_NODE_TYPE("SORTBY"); @@ -3191,6 +3203,9 @@ _outNode(StringInfo str, const void *obj) case T_ResTarget: _outResTarget(str, obj); break; + case T_MultiAssignRef: + _outMultiAssignRef(str, obj); + break; case T_SortBy: _outSortBy(str, obj); break; |
