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/nodeFuncs.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/nodeFuncs.c')
-rw-r--r-- | src/backend/nodes/nodeFuncs.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/backend/nodes/nodeFuncs.c b/src/backend/nodes/nodeFuncs.c index f4999c5be03..41e973b1236 100644 --- a/src/backend/nodes/nodeFuncs.c +++ b/src/backend/nodes/nodeFuncs.c @@ -116,6 +116,11 @@ exprType(const Node *expr) format_type_be(exprType((Node *) tent->expr))))); } } + else if (sublink->subLinkType == MULTIEXPR_SUBLINK) + { + /* MULTIEXPR is always considered to return RECORD */ + type = RECORDOID; + } else { /* for all other sublink types, result is boolean */ @@ -142,6 +147,11 @@ exprType(const Node *expr) format_type_be(subplan->firstColType)))); } } + else if (subplan->subLinkType == MULTIEXPR_SUBLINK) + { + /* MULTIEXPR is always considered to return RECORD */ + type = RECORDOID; + } else { /* for all other subplan types, result is boolean */ @@ -299,6 +309,7 @@ exprTypmod(const Node *expr) return exprTypmod((Node *) tent->expr); /* note we don't need to care if it's an array */ } + /* otherwise, result is RECORD or BOOLEAN, typmod is -1 */ } break; case T_SubPlan: @@ -312,11 +323,7 @@ exprTypmod(const Node *expr) /* note we don't need to care if it's an array */ return subplan->firstColTypmod; } - else - { - /* for all other subplan types, result is boolean */ - return -1; - } + /* otherwise, result is RECORD or BOOLEAN, typmod is -1 */ } break; case T_AlternativeSubPlan: @@ -784,7 +791,7 @@ exprCollation(const Node *expr) } else { - /* for all other sublink types, result is boolean */ + /* otherwise, result is RECORD or BOOLEAN */ coll = InvalidOid; } } @@ -802,7 +809,7 @@ exprCollation(const Node *expr) } else { - /* for all other subplan types, result is boolean */ + /* otherwise, result is RECORD or BOOLEAN */ coll = InvalidOid; } } @@ -1017,7 +1024,7 @@ exprSetCollation(Node *expr, Oid collation) } else { - /* for all other sublink types, result is boolean */ + /* otherwise, result is RECORD or BOOLEAN */ Assert(!OidIsValid(collation)); } } @@ -1420,6 +1427,9 @@ exprLocation(const Node *expr) /* we need not examine the contained expression (if any) */ loc = ((const ResTarget *) expr)->location; break; + case T_MultiAssignRef: + loc = exprLocation(((const MultiAssignRef *) expr)->source); + break; case T_TypeCast: { const TypeCast *tc = (const TypeCast *) expr; @@ -3107,6 +3117,8 @@ raw_expression_tree_walker(Node *node, return true; } break; + case T_MultiAssignRef: + return walker(((MultiAssignRef *) node)->source, context); case T_TypeCast: { TypeCast *tc = (TypeCast *) node; |