From: | Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> |
---|---|
To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
Subject: | pgsql: Add RETURNING support to MERGE. |
Date: | 2024-03-17 14:04:41 |
Message-ID: | E1rlr7w-004I1h-Sg@gemulon.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-committers |
Add RETURNING support to MERGE.
This allows a RETURNING clause to be appended to a MERGE query, to
return values based on each row inserted, updated, or deleted. As with
plain INSERT, UPDATE, and DELETE commands, the returned values are
based on the new contents of the target table for INSERT and UPDATE
actions, and on its old contents for DELETE actions. Values from the
source relation may also be returned.
As with INSERT/UPDATE/DELETE, the output of MERGE ... RETURNING may be
used as the source relation for other operations such as WITH queries
and COPY commands.
Additionally, a special function merge_action() is provided, which
returns 'INSERT', 'UPDATE', or 'DELETE', depending on the action
executed for each row. The merge_action() function can be used
anywhere in the RETURNING list, including in arbitrary expressions and
subqueries, but it is an error to use it anywhere outside of a MERGE
query's RETURNING list.
Dean Rasheed, reviewed by Isaac Morland, Vik Fearing, Alvaro Herrera,
Gurjeet Singh, Jian He, Jeff Davis, Merlin Moncure, Peter Eisentraut,
and Wolfgang Walther.
Discussion: http://postgr.es/m/CAEZATCWePEGQR5LBn-vD6SfeLZafzEm2Qy_L_Oky2=qw2w3Pzg@mail.gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/c649fa24a42ba89bf5460c7110e4fc8eeca65959
Modified Files
--------------
doc/src/sgml/dml.sgml | 22 ++-
doc/src/sgml/func.sgml | 79 ++++++++
doc/src/sgml/glossary.sgml | 6 +-
doc/src/sgml/plpgsql.sgml | 16 +-
doc/src/sgml/queries.sgml | 9 +-
doc/src/sgml/ref/copy.sgml | 19 +-
doc/src/sgml/ref/merge.sgml | 68 +++++--
doc/src/sgml/ref/select.sgml | 11 +-
doc/src/sgml/rowtypes.sgml | 2 +-
doc/src/sgml/spi.sgml | 14 +-
doc/src/sgml/xfunc.sgml | 8 +-
src/backend/commands/copy.c | 6 -
src/backend/commands/copyto.c | 3 +-
src/backend/executor/execExpr.c | 13 ++
src/backend/executor/execExprInterp.c | 48 +++++
src/backend/executor/execPartition.c | 8 +-
src/backend/executor/functions.c | 9 +-
src/backend/executor/nodeModifyTable.c | 202 +++++++++++++------
src/backend/executor/spi.c | 7 +-
src/backend/jit/llvm/llvmjit_expr.c | 6 +
src/backend/jit/llvm/llvmjit_types.c | 1 +
src/backend/nodes/nodeFuncs.c | 17 ++
src/backend/optimizer/plan/subselect.c | 9 +-
src/backend/optimizer/util/paramassign.c | 51 +++++
src/backend/parser/analyze.c | 19 +-
src/backend/parser/gram.y | 14 +-
src/backend/parser/parse_agg.c | 2 +
src/backend/parser/parse_cte.c | 10 +-
src/backend/parser/parse_expr.c | 34 ++++
src/backend/parser/parse_func.c | 1 +
src/backend/parser/parse_merge.c | 7 +-
src/backend/parser/parse_relation.c | 7 +-
src/backend/parser/parse_target.c | 4 +
src/backend/rewrite/rewriteHandler.c | 9 +-
src/backend/rewrite/rowsecurity.c | 28 ++-
src/backend/tcop/utility.c | 3 +-
src/backend/utils/adt/ruleutils.c | 14 +-
src/bin/psql/common.c | 8 +-
src/include/catalog/catversion.h | 2 +-
src/include/executor/execExpr.h | 3 +
src/include/executor/spi.h | 1 +
src/include/nodes/execnodes.h | 3 +
src/include/nodes/parsenodes.h | 1 +
src/include/nodes/primnodes.h | 21 ++
src/include/optimizer/paramassign.h | 2 +
src/include/parser/analyze.h | 2 +
src/include/parser/kwlist.h | 1 +
src/include/parser/parse_node.h | 3 +-
src/pl/plpgsql/src/pl_exec.c | 12 +-
src/pl/tcl/pltcl.c | 1 +
src/test/regress/expected/merge.out | 266 ++++++++++++++++++++++++--
src/test/regress/expected/rowsecurity.out | 32 +++-
src/test/regress/expected/rules.out | 16 +-
src/test/regress/expected/updatable_views.out | 30 ++-
src/test/regress/expected/with.out | 10 +
src/test/regress/sql/merge.sql | 169 ++++++++++++++--
src/test/regress/sql/rowsecurity.sql | 21 ++
src/test/regress/sql/rules.sql | 6 +-
src/test/regress/sql/updatable_views.sql | 9 +-
src/test/regress/sql/with.sql | 8 +
src/tools/pgindent/typedefs.list | 1 +
61 files changed, 1198 insertions(+), 216 deletions(-)
From | Date | Subject | |
---|---|---|---|
Next Message | Dean Rasheed | 2024-03-17 14:50:02 | pgsql: Fix PDF doc generation. |
Previous Message | Peter Eisentraut | 2024-03-17 11:53:21 | pgsql: Generalize handling of nullable pg_attribute columns in DDL |