1/*-------------------------------------------------------------------------
4 * Internal definitions for parser
7 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/include/parser/parse_node.h
12 *-------------------------------------------------------------------------
22/* Forward references for some structs declared below */
28 * Expression kinds distinguished by transformExpr(). Many of these are not
29 * semantically distinct so far as expression transformation goes; rather,
30 * we distinguish them so that context-specific error messages can be printed.
32 * Note: EXPR_KIND_OTHER is not used in the core code, but is left for use
33 * by extension code that might need to call transformExpr(). The core code
34 * will not enforce any context-driven restrictions on EXPR_KIND_OTHER
35 * expressions, so the caller would have to check for sub-selects, aggregates,
36 * window functions, SRFs, etc if those need to be disallowed.
89 * Function signatures for parser hooks
95 Oid targetTypeId,
int32 targetTypeMod,
100 * State information used during parse analysis
102 * parentParseState: NULL in a top-level ParseState. When parsing a subquery,
103 * links to current parse state of outer query.
105 * p_sourcetext: source string that generated the raw parsetree being
106 * analyzed, or NULL if not available. (The string is used only to
107 * generate cursor positions in error messages: we need it to convert
108 * byte-wise locations in parse structures to character-wise cursor
111 * p_rtable: list of RTEs that will become the rangetable of the query.
112 * Note that neither relname nor refname of these entries are necessarily
113 * unique; searching the rtable by name is a bad idea.
115 * p_rteperminfos: list of RTEPermissionInfo containing an entry corresponding
116 * to each RTE_RELATION entry in p_rtable.
118 * p_joinexprs: list of JoinExpr nodes associated with p_rtable entries.
119 * This is one-for-one with p_rtable, but contains NULLs for non-join
120 * RTEs, and may be shorter than p_rtable if the last RTE(s) aren't joins.
122 * p_nullingrels: list of Bitmapsets associated with p_rtable entries, each
123 * containing the set of outer-join RTE indexes that can null that relation
124 * at the current point in the parse tree. This is one-for-one with p_rtable,
125 * but may be shorter than p_rtable, in which case the missing entries are
126 * implicitly empty (NULL). That rule allows us to save work when the query
127 * contains no outer joins.
129 * p_joinlist: list of join items (RangeTblRef and JoinExpr nodes) that
130 * will become the fromlist of the query's top-level FromExpr node.
132 * p_namespace: list of ParseNamespaceItems that represents the current
133 * namespace for table and column lookup. (The RTEs listed here may be just
134 * a subset of the whole rtable. See ParseNamespaceItem comments below.)
136 * p_lateral_active: true if we are currently parsing a LATERAL subexpression
137 * of this parse level. This makes p_lateral_only namespace items visible,
138 * whereas they are not visible when p_lateral_active is FALSE.
140 * p_ctenamespace: list of CommonTableExprs (WITH items) that are visible
141 * at the moment. This is entirely different from p_namespace because a CTE
142 * is not an RTE, rather "visibility" means you could make an RTE from it.
144 * p_future_ctes: list of CommonTableExprs (WITH items) that are not yet
145 * visible due to scope rules. This is used to help improve error messages.
147 * p_parent_cte: CommonTableExpr that immediately contains the current query,
150 * p_target_relation: target relation, if query is INSERT/UPDATE/DELETE/MERGE
152 * p_target_nsitem: target relation's ParseNamespaceItem.
154 * p_grouping_nsitem: the ParseNamespaceItem that represents the grouping step.
156 * p_is_insert: true to process assignment expressions like INSERT, false
157 * to process them like UPDATE. (Note this can change intra-statement, for
158 * cases like INSERT ON CONFLICT UPDATE.)
160 * p_windowdefs: list of WindowDefs representing WINDOW and OVER clauses.
161 * We collect these while transforming expressions and then transform them
162 * afterwards (so that any resjunk tlist items needed for the sort/group
163 * clauses end up at the end of the query tlist). A WindowDef's location in
164 * this list, counting from 1, is the winref number to use to reference it.
166 * p_expr_kind: kind of expression we're currently parsing, as per enum above;
167 * EXPR_KIND_NONE when not in an expression.
169 * p_next_resno: next TargetEntry.resno to assign, starting from 1.
171 * p_multiassign_exprs: partially-processed MultiAssignRef source expressions.
173 * p_locking_clause: query's FOR UPDATE/FOR SHARE clause, if any.
175 * p_locked_from_parent: true if parent query level applies FOR UPDATE/SHARE
176 * to this subquery as a whole.
178 * p_resolve_unknowns: resolve unknown-type SELECT output columns as type TEXT
179 * (this is true by default).
181 * p_hasAggs, p_hasWindowFuncs, etc: true if we've found any of the indicated
182 * constructs in the query.
184 * p_last_srf: the set-returning FuncExpr or OpExpr most recently found in
185 * the query, or NULL if none.
187 * p_pre_columnref_hook, etc: optional parser hook functions for modifying the
188 * interpretation of ColumnRefs and ParamRefs.
190 * p_ref_hook_state: passthrough state for the parser hook functions.
198 * RTE_RELATION entry in rtable */
202 * node's fromlist) */
204 * ParseNamespaceItem) */
219 * with FOR UPDATE/FOR SHARE */
225 /* Flags telling about things found in the query: */
235 * Optional hook functions for parser callbacks. These are null unless
236 * set up by the caller of make_parsestate.
246 * An element of a namespace list.
248 * p_names contains the table name and column names exposed by this nsitem.
249 * (Typically it's equal to p_rte->eref, but for a JOIN USING alias it's
250 * equal to p_rte->join_using_alias. Since the USING columns will be the
251 * join's first N columns, the net effect is just that we expose only those
252 * join columns via this nsitem.)
254 * p_rte and p_rtindex link to the underlying rangetable entry, and
255 * p_perminfo to the entry in rteperminfos.
257 * The p_nscolumns array contains info showing how to construct Vars
258 * referencing the names appearing in the p_names->colnames list.
260 * Namespace items with p_rel_visible set define which RTEs are accessible by
261 * qualified names, while those with p_cols_visible set define which RTEs are
262 * accessible by unqualified names. These sets are different because a JOIN
263 * without an alias does not hide the contained tables (so they must be
264 * visible for qualified references) but it does hide their columns
265 * (unqualified references to the columns refer to the JOIN, not the member
266 * tables, so we must not complain that such a reference is ambiguous).
267 * Conversely, a subquery without an alias does not hide the columns selected
268 * by the subquery, but it does hide the auto-generated relation name (so the
269 * subquery columns are visible for unqualified references only). Various
270 * special RTEs such as NEW/OLD for rules may also appear with only one flag
273 * While processing the FROM clause, namespace items may appear with
274 * p_lateral_only set, meaning they are visible only to LATERAL
275 * subexpressions. (The pstate's p_lateral_active flag tells whether we are
276 * inside such a subexpression at the moment.) If p_lateral_ok is not set,
277 * it's an error to actually use such a namespace item. One might think it
278 * would be better to just exclude such items from visibility, but the wording
279 * of SQL:2008 requires us to do it this way. We also use p_lateral_ok to
280 * forbid LATERAL references to an UPDATE/DELETE target table.
282 * While processing the RETURNING clause, special namespace items are added to
283 * refer to the OLD and NEW state of the result relation. These namespace
284 * items have p_returning_type set appropriately, for use when creating Vars.
285 * For convenience, this information is duplicated on each namespace column.
287 * At no time should a namespace list contain two entries that conflict
288 * according to the rules in checkNameSpaceConflicts; but note that those
289 * are more complicated than "must have different alias names", so in practice
290 * code searching a namespace list has to check for ambiguous references.
296 int p_rtindex;
/* The relation's index in the rangetable */
298 /* array of same length as p_names->colnames: */
308 * Data about one column of a ParseNamespaceItem.
310 * We track the info needed to construct a Var referencing the column
311 * (but only for user-defined columns; system column references and
312 * whole-row references are handled separately).
314 * p_varno and p_varattno identify the semantic referent, which is a
315 * base-relation column unless the reference is to a join USING column that
316 * isn't semantically equivalent to either join input column (because it is a
317 * FULL join or the input column requires a type coercion). In those cases
318 * p_varno and p_varattno refer to the JOIN RTE.
320 * p_varnosyn and p_varattnosyn are either identical to p_varno/p_varattno,
321 * or they specify the column's position in an aliased JOIN RTE that hides
322 * the semantic referent RTE's refname. (That could be either the JOIN RTE
323 * in which this ParseNamespaceColumn entry exists, or some lower join level.)
325 * If an RTE contains a dropped column, its ParseNamespaceColumn struct
326 * is all-zeroes. (Conventionally, test for p_varno == 0 to detect this.)
341/* Support for parser_errposition_callback function */
363 int32 containerTypMod,
368#endif /* PARSE_NODE_H */
void cancel_parser_errposition_callback(ParseCallbackState *pcbstate)
void free_parsestate(ParseState *pstate)
Node *(* PostParseColumnRefHook)(ParseState *pstate, ColumnRef *cref, Node *var)
Node *(* PreParseColumnRefHook)(ParseState *pstate, ColumnRef *cref)
int parser_errposition(ParseState *pstate, int location)
SubscriptingRef * transformContainerSubscripts(ParseState *pstate, Node *containerBase, Oid containerType, int32 containerTypMod, List *indirection, bool isAssignment)
void setup_parser_errposition_callback(ParseCallbackState *pcbstate, ParseState *pstate, int location)
Node *(* ParseParamRefHook)(ParseState *pstate, ParamRef *pref)
@ EXPR_KIND_EXECUTE_PARAMETER
@ EXPR_KIND_COLUMN_DEFAULT
@ EXPR_KIND_STATS_EXPRESSION
@ EXPR_KIND_INDEX_EXPRESSION
@ EXPR_KIND_MERGE_RETURNING
@ EXPR_KIND_PARTITION_BOUND
@ EXPR_KIND_FUNCTION_DEFAULT
@ EXPR_KIND_WINDOW_FRAME_RANGE
@ EXPR_KIND_FROM_SUBSELECT
@ EXPR_KIND_WINDOW_FRAME_GROUPS
@ EXPR_KIND_PARTITION_EXPRESSION
@ EXPR_KIND_INDEX_PREDICATE
@ EXPR_KIND_INSERT_TARGET
@ EXPR_KIND_ALTER_COL_TRANSFORM
@ EXPR_KIND_UPDATE_TARGET
@ EXPR_KIND_SELECT_TARGET
@ EXPR_KIND_GENERATED_COLUMN
@ EXPR_KIND_CALL_ARGUMENT
@ EXPR_KIND_FROM_FUNCTION
@ EXPR_KIND_UPDATE_SOURCE
@ EXPR_KIND_CHECK_CONSTRAINT
@ EXPR_KIND_WINDOW_PARTITION
@ EXPR_KIND_WINDOW_FRAME_ROWS
@ EXPR_KIND_VALUES_SINGLE
Const * make_const(ParseState *pstate, A_Const *aconst)
void transformContainerType(Oid *containerType, int32 *containerTypmod)
ParseState * make_parsestate(ParseState *parentParseState)
struct ParseCallbackState ParseCallbackState
Node *(* CoerceParamHook)(ParseState *pstate, Param *param, Oid targetTypeId, int32 targetTypeMod, int location)
ErrorContextCallback errcallback
VarReturningType p_varreturningtype
ParseNamespaceColumn * p_nscolumns
RTEPermissionInfo * p_perminfo
VarReturningType p_returning_type
ParseState * parentParseState
ParseNamespaceItem * p_target_nsitem
ParseNamespaceItem * p_grouping_nsitem
ParseExprKind p_expr_kind
List * p_multiassign_exprs
bool p_locked_from_parent
ParseParamRefHook p_paramref_hook
PreParseColumnRefHook p_pre_columnref_hook
QueryEnvironment * p_queryEnv
const char * p_sourcetext
Relation p_target_relation
CommonTableExpr * p_parent_cte
CoerceParamHook p_coerce_param_hook
PostParseColumnRefHook p_post_columnref_hook