mirror of
https://git.postgresql.org/git/postgresql.git
synced 2026-02-18 12:26:59 +08:00
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
67 lines
2.6 KiB
C
67 lines
2.6 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* analyze.h
|
|
* parse analysis for optimizable statements
|
|
*
|
|
*
|
|
* Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
* src/include/parser/analyze.h
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#ifndef ANALYZE_H
|
|
#define ANALYZE_H
|
|
|
|
#include "nodes/params.h"
|
|
#include "nodes/queryjumble.h"
|
|
#include "parser/parse_node.h"
|
|
|
|
/* Hook for plugins to get control at end of parse analysis */
|
|
typedef void (*post_parse_analyze_hook_type) (ParseState *pstate,
|
|
Query *query,
|
|
JumbleState *jstate);
|
|
extern PGDLLIMPORT post_parse_analyze_hook_type post_parse_analyze_hook;
|
|
|
|
|
|
extern Query *parse_analyze_fixedparams(RawStmt *parseTree, const char *sourceText,
|
|
const Oid *paramTypes, int numParams, QueryEnvironment *queryEnv);
|
|
extern Query *parse_analyze_varparams(RawStmt *parseTree, const char *sourceText,
|
|
Oid **paramTypes, int *numParams, QueryEnvironment *queryEnv);
|
|
extern Query *parse_analyze_withcb(RawStmt *parseTree, const char *sourceText,
|
|
ParserSetupHook parserSetup,
|
|
void *parserSetupArg,
|
|
QueryEnvironment *queryEnv);
|
|
|
|
extern Query *parse_sub_analyze(Node *parseTree, ParseState *parentParseState,
|
|
CommonTableExpr *parentCTE,
|
|
bool locked_from_parent,
|
|
bool resolve_unknowns);
|
|
|
|
extern List *transformInsertRow(ParseState *pstate, List *exprlist,
|
|
List *stmtcols, List *icolumns, List *attrnos,
|
|
bool strip_indirection);
|
|
extern List *transformUpdateTargetList(ParseState *pstate,
|
|
List *origTlist);
|
|
extern List *transformReturningList(ParseState *pstate, List *returningList,
|
|
ParseExprKind exprKind);
|
|
extern Query *transformTopLevelStmt(ParseState *pstate, RawStmt *parseTree);
|
|
extern Query *transformStmt(ParseState *pstate, Node *parseTree);
|
|
|
|
extern bool stmt_requires_parse_analysis(RawStmt *parseTree);
|
|
extern bool analyze_requires_snapshot(RawStmt *parseTree);
|
|
|
|
extern const char *LCS_asString(LockClauseStrength strength);
|
|
extern void CheckSelectLocking(Query *qry, LockClauseStrength strength);
|
|
extern void applyLockingClause(Query *qry, Index rtindex,
|
|
LockClauseStrength strength,
|
|
LockWaitPolicy waitPolicy, bool pushedDown);
|
|
|
|
extern List *BuildOnConflictExcludedTargetlist(Relation targetrel,
|
|
Index exclRelIndex);
|
|
|
|
extern SortGroupClause *makeSortGroupClauseForSetOp(Oid rescoltype, bool require_hash);
|
|
|
|
#endif /* ANALYZE_H */
|