mirror of
https://github.com/postgres/postgres.git
synced 2026-01-27 21:43:08 +03:00
This allows the RETURNING list of INSERT/UPDATE/DELETE/MERGE queries to explicitly return old and new values by using the special aliases "old" and "new", which are automatically added to the query (if not already defined) while parsing its RETURNING list, allowing things like: RETURNING old.colname, new.colname, ... RETURNING old.*, new.* Additionally, a new syntax is supported, allowing the names "old" and "new" to be changed to user-supplied alias names, e.g.: RETURNING WITH (OLD AS o, NEW AS n) o.colname, n.colname, ... This is useful when the names "old" and "new" are already defined, such as inside trigger functions, allowing backwards compatibility to be maintained -- the interpretation of any existing queries that happen to already refer to relations called "old" or "new", or use those as aliases for other relations, is not changed. For an INSERT, old values will generally be NULL, and for a DELETE, new values will generally be NULL, but that may change for an INSERT with an ON CONFLICT ... DO UPDATE clause, or if a query rewrite rule changes the command type. Therefore, we put no restrictions on the use of old and new in any DML queries. Dean Rasheed, reviewed by Jian He and Jeff Davis. Discussion: https://postgr.es/m/CAEZATCWx0J0-v=Qjc6gXzR=KtsdvAE7Ow=D=mu50AgOe+pvisQ@mail.gmail.com
68 lines
2.6 KiB
C
68 lines
2.6 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* analyze.h
|
|
* parse analysis for optimizable statements
|
|
*
|
|
*
|
|
* Portions Copyright (c) 1996-2025, 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 void transformReturningClause(ParseState *pstate, Query *qry,
|
|
ReturningClause *returningClause,
|
|
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 */
|