]> granicus.if.org Git - postgresql/commit
Implement UPDATE tab SET (col1,col2,...) = (SELECT ...), ...
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 18 Jun 2014 17:22:25 +0000 (13:22 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 18 Jun 2014 17:22:34 +0000 (13:22 -0400)
commit8f889b1083f38f4f5b3bd3512008a3f60e939244
tree68c2e242c88245ea0d3b9329e1e27c78a8e70eaf
parent230ba02d855de7fac31bfb6af25ebd4ae052640b
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))".
31 files changed:
contrib/pg_stat_statements/pg_stat_statements.c
doc/src/sgml/ref/update.sgml
doc/src/sgml/rules.sgml
src/backend/executor/nodeSubplan.c
src/backend/nodes/copyfuncs.c
src/backend/nodes/equalfuncs.c
src/backend/nodes/list.c
src/backend/nodes/nodeFuncs.c
src/backend/nodes/outfuncs.c
src/backend/nodes/readfuncs.c
src/backend/optimizer/plan/planner.c
src/backend/optimizer/plan/setrefs.c
src/backend/optimizer/plan/subselect.c
src/backend/optimizer/prep/prepjointree.c
src/backend/optimizer/util/tlist.c
src/backend/parser/gram.y
src/backend/parser/parse_expr.c
src/backend/parser/parse_target.c
src/backend/rewrite/rewriteManip.c
src/backend/utils/adt/ruleutils.c
src/include/catalog/catversion.h
src/include/nodes/execnodes.h
src/include/nodes/nodes.h
src/include/nodes/parsenodes.h
src/include/nodes/pg_list.h
src/include/nodes/primnodes.h
src/include/nodes/relation.h
src/include/optimizer/tlist.h
src/include/parser/parse_node.h
src/test/regress/expected/update.out
src/test/regress/sql/update.sql