PostgreSQL Source Code  git master
parse_node.h File Reference
Include dependency graph for parse_node.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ParseState
 
struct  ParseNamespaceItem
 
struct  ParseNamespaceColumn
 
struct  ParseCallbackState
 

Typedefs

typedef struct ParseState ParseState
 
typedef struct ParseNamespaceItem ParseNamespaceItem
 
typedef struct ParseNamespaceColumn ParseNamespaceColumn
 
typedef enum ParseExprKind ParseExprKind
 
typedef Node *(* PreParseColumnRefHook) (ParseState *pstate, ColumnRef *cref)
 
typedef Node *(* PostParseColumnRefHook) (ParseState *pstate, ColumnRef *cref, Node *var)
 
typedef Node *(* ParseParamRefHook) (ParseState *pstate, ParamRef *pref)
 
typedef Node *(* CoerceParamHook) (ParseState *pstate, Param *param, Oid targetTypeId, int32 targetTypeMod, int location)
 
typedef struct ParseCallbackState ParseCallbackState
 

Enumerations

enum  ParseExprKind {
  EXPR_KIND_NONE = 0 , EXPR_KIND_OTHER , EXPR_KIND_JOIN_ON , EXPR_KIND_JOIN_USING ,
  EXPR_KIND_FROM_SUBSELECT , EXPR_KIND_FROM_FUNCTION , EXPR_KIND_WHERE , EXPR_KIND_HAVING ,
  EXPR_KIND_FILTER , EXPR_KIND_WINDOW_PARTITION , EXPR_KIND_WINDOW_ORDER , EXPR_KIND_WINDOW_FRAME_RANGE ,
  EXPR_KIND_WINDOW_FRAME_ROWS , EXPR_KIND_WINDOW_FRAME_GROUPS , EXPR_KIND_SELECT_TARGET , EXPR_KIND_INSERT_TARGET ,
  EXPR_KIND_UPDATE_SOURCE , EXPR_KIND_UPDATE_TARGET , EXPR_KIND_MERGE_WHEN , EXPR_KIND_GROUP_BY ,
  EXPR_KIND_ORDER_BY , EXPR_KIND_DISTINCT_ON , EXPR_KIND_LIMIT , EXPR_KIND_OFFSET ,
  EXPR_KIND_RETURNING , EXPR_KIND_MERGE_RETURNING , EXPR_KIND_VALUES , EXPR_KIND_VALUES_SINGLE ,
  EXPR_KIND_CHECK_CONSTRAINT , EXPR_KIND_DOMAIN_CHECK , EXPR_KIND_COLUMN_DEFAULT , EXPR_KIND_FUNCTION_DEFAULT ,
  EXPR_KIND_INDEX_EXPRESSION , EXPR_KIND_INDEX_PREDICATE , EXPR_KIND_STATS_EXPRESSION , EXPR_KIND_ALTER_COL_TRANSFORM ,
  EXPR_KIND_EXECUTE_PARAMETER , EXPR_KIND_TRIGGER_WHEN , EXPR_KIND_POLICY , EXPR_KIND_PARTITION_BOUND ,
  EXPR_KIND_PARTITION_EXPRESSION , EXPR_KIND_CALL_ARGUMENT , EXPR_KIND_COPY_WHERE , EXPR_KIND_GENERATED_COLUMN ,
  EXPR_KIND_CYCLE_MARK
}
 

Functions

ParseStatemake_parsestate (ParseState *parentParseState)
 
void free_parsestate (ParseState *pstate)
 
int parser_errposition (ParseState *pstate, int location)
 
void setup_parser_errposition_callback (ParseCallbackState *pcbstate, ParseState *pstate, int location)
 
void cancel_parser_errposition_callback (ParseCallbackState *pcbstate)
 
void transformContainerType (Oid *containerType, int32 *containerTypmod)
 
SubscriptingReftransformContainerSubscripts (ParseState *pstate, Node *containerBase, Oid containerType, int32 containerTypMod, List *indirection, bool isAssignment)
 
Constmake_const (ParseState *pstate, A_Const *aconst)
 

Typedef Documentation

◆ CoerceParamHook

typedef Node*(* CoerceParamHook) (ParseState *pstate, Param *param, Oid targetTypeId, int32 targetTypeMod, int location)

Definition at line 94 of file parse_node.h.

◆ ParseCallbackState

◆ ParseExprKind

◆ ParseNamespaceColumn

Definition at line 1 of file parse_node.h.

◆ ParseNamespaceItem

Definition at line 1 of file parse_node.h.

◆ ParseParamRefHook

typedef Node*(* ParseParamRefHook) (ParseState *pstate, ParamRef *pref)

Definition at line 93 of file parse_node.h.

◆ ParseState

typedef struct ParseState ParseState

Definition at line 1 of file parse_node.h.

◆ PostParseColumnRefHook

typedef Node*(* PostParseColumnRefHook) (ParseState *pstate, ColumnRef *cref, Node *var)

Definition at line 92 of file parse_node.h.

◆ PreParseColumnRefHook

typedef Node*(* PreParseColumnRefHook) (ParseState *pstate, ColumnRef *cref)

Definition at line 91 of file parse_node.h.

Enumeration Type Documentation

◆ ParseExprKind

Enumerator
EXPR_KIND_NONE 
EXPR_KIND_OTHER 
EXPR_KIND_JOIN_ON 
EXPR_KIND_JOIN_USING 
EXPR_KIND_FROM_SUBSELECT 
EXPR_KIND_FROM_FUNCTION 
EXPR_KIND_WHERE 
EXPR_KIND_HAVING 
EXPR_KIND_FILTER 
EXPR_KIND_WINDOW_PARTITION 
EXPR_KIND_WINDOW_ORDER 
EXPR_KIND_WINDOW_FRAME_RANGE 
EXPR_KIND_WINDOW_FRAME_ROWS 
EXPR_KIND_WINDOW_FRAME_GROUPS 
EXPR_KIND_SELECT_TARGET 
EXPR_KIND_INSERT_TARGET 
EXPR_KIND_UPDATE_SOURCE 
EXPR_KIND_UPDATE_TARGET 
EXPR_KIND_MERGE_WHEN 
EXPR_KIND_GROUP_BY 
EXPR_KIND_ORDER_BY 
EXPR_KIND_DISTINCT_ON 
EXPR_KIND_LIMIT 
EXPR_KIND_OFFSET 
EXPR_KIND_RETURNING 
EXPR_KIND_MERGE_RETURNING 
EXPR_KIND_VALUES 
EXPR_KIND_VALUES_SINGLE 
EXPR_KIND_CHECK_CONSTRAINT 
EXPR_KIND_DOMAIN_CHECK 
EXPR_KIND_COLUMN_DEFAULT 
EXPR_KIND_FUNCTION_DEFAULT 
EXPR_KIND_INDEX_EXPRESSION 
EXPR_KIND_INDEX_PREDICATE 
EXPR_KIND_STATS_EXPRESSION 
EXPR_KIND_ALTER_COL_TRANSFORM 
EXPR_KIND_EXECUTE_PARAMETER 
EXPR_KIND_TRIGGER_WHEN 
EXPR_KIND_POLICY 
EXPR_KIND_PARTITION_BOUND 
EXPR_KIND_PARTITION_EXPRESSION 
EXPR_KIND_CALL_ARGUMENT 
EXPR_KIND_COPY_WHERE 
EXPR_KIND_GENERATED_COLUMN 
EXPR_KIND_CYCLE_MARK 

Definition at line 38 of file parse_node.h.

39 {
40  EXPR_KIND_NONE = 0, /* "not in an expression" */
41  EXPR_KIND_OTHER, /* reserved for extensions */
42  EXPR_KIND_JOIN_ON, /* JOIN ON */
43  EXPR_KIND_JOIN_USING, /* JOIN USING */
44  EXPR_KIND_FROM_SUBSELECT, /* sub-SELECT in FROM clause */
45  EXPR_KIND_FROM_FUNCTION, /* function in FROM clause */
46  EXPR_KIND_WHERE, /* WHERE */
47  EXPR_KIND_HAVING, /* HAVING */
48  EXPR_KIND_FILTER, /* FILTER */
49  EXPR_KIND_WINDOW_PARTITION, /* window definition PARTITION BY */
50  EXPR_KIND_WINDOW_ORDER, /* window definition ORDER BY */
51  EXPR_KIND_WINDOW_FRAME_RANGE, /* window frame clause with RANGE */
52  EXPR_KIND_WINDOW_FRAME_ROWS, /* window frame clause with ROWS */
53  EXPR_KIND_WINDOW_FRAME_GROUPS, /* window frame clause with GROUPS */
54  EXPR_KIND_SELECT_TARGET, /* SELECT target list item */
55  EXPR_KIND_INSERT_TARGET, /* INSERT target list item */
56  EXPR_KIND_UPDATE_SOURCE, /* UPDATE assignment source item */
57  EXPR_KIND_UPDATE_TARGET, /* UPDATE assignment target item */
58  EXPR_KIND_MERGE_WHEN, /* MERGE WHEN [NOT] MATCHED condition */
59  EXPR_KIND_GROUP_BY, /* GROUP BY */
60  EXPR_KIND_ORDER_BY, /* ORDER BY */
61  EXPR_KIND_DISTINCT_ON, /* DISTINCT ON */
62  EXPR_KIND_LIMIT, /* LIMIT */
63  EXPR_KIND_OFFSET, /* OFFSET */
64  EXPR_KIND_RETURNING, /* RETURNING in INSERT/UPDATE/DELETE */
65  EXPR_KIND_MERGE_RETURNING, /* RETURNING in MERGE */
66  EXPR_KIND_VALUES, /* VALUES */
67  EXPR_KIND_VALUES_SINGLE, /* single-row VALUES (in INSERT only) */
68  EXPR_KIND_CHECK_CONSTRAINT, /* CHECK constraint for a table */
69  EXPR_KIND_DOMAIN_CHECK, /* CHECK constraint for a domain */
70  EXPR_KIND_COLUMN_DEFAULT, /* default value for a table column */
71  EXPR_KIND_FUNCTION_DEFAULT, /* default parameter value for function */
72  EXPR_KIND_INDEX_EXPRESSION, /* index expression */
73  EXPR_KIND_INDEX_PREDICATE, /* index predicate */
74  EXPR_KIND_STATS_EXPRESSION, /* extended statistics expression */
75  EXPR_KIND_ALTER_COL_TRANSFORM, /* transform expr in ALTER COLUMN TYPE */
76  EXPR_KIND_EXECUTE_PARAMETER, /* parameter value in EXECUTE */
77  EXPR_KIND_TRIGGER_WHEN, /* WHEN condition in CREATE TRIGGER */
78  EXPR_KIND_POLICY, /* USING or WITH CHECK expr in policy */
79  EXPR_KIND_PARTITION_BOUND, /* partition bound expression */
80  EXPR_KIND_PARTITION_EXPRESSION, /* PARTITION BY expression */
81  EXPR_KIND_CALL_ARGUMENT, /* procedure argument in CALL */
82  EXPR_KIND_COPY_WHERE, /* WHERE condition in COPY FROM */
83  EXPR_KIND_GENERATED_COLUMN, /* generation expression for a column */
84  EXPR_KIND_CYCLE_MARK, /* cycle mark value */
ParseExprKind
Definition: parse_node.h:39
@ EXPR_KIND_EXECUTE_PARAMETER
Definition: parse_node.h:76
@ EXPR_KIND_DOMAIN_CHECK
Definition: parse_node.h:69
@ EXPR_KIND_COPY_WHERE
Definition: parse_node.h:82
@ EXPR_KIND_COLUMN_DEFAULT
Definition: parse_node.h:70
@ EXPR_KIND_DISTINCT_ON
Definition: parse_node.h:61
@ EXPR_KIND_MERGE_WHEN
Definition: parse_node.h:58
@ EXPR_KIND_STATS_EXPRESSION
Definition: parse_node.h:74
@ EXPR_KIND_INDEX_EXPRESSION
Definition: parse_node.h:72
@ EXPR_KIND_MERGE_RETURNING
Definition: parse_node.h:65
@ EXPR_KIND_PARTITION_BOUND
Definition: parse_node.h:79
@ EXPR_KIND_FUNCTION_DEFAULT
Definition: parse_node.h:71
@ EXPR_KIND_WINDOW_FRAME_RANGE
Definition: parse_node.h:51
@ EXPR_KIND_VALUES
Definition: parse_node.h:66
@ EXPR_KIND_FROM_SUBSELECT
Definition: parse_node.h:44
@ EXPR_KIND_POLICY
Definition: parse_node.h:78
@ EXPR_KIND_WINDOW_FRAME_GROUPS
Definition: parse_node.h:53
@ EXPR_KIND_PARTITION_EXPRESSION
Definition: parse_node.h:80
@ EXPR_KIND_JOIN_USING
Definition: parse_node.h:43
@ EXPR_KIND_INDEX_PREDICATE
Definition: parse_node.h:73
@ EXPR_KIND_ORDER_BY
Definition: parse_node.h:60
@ EXPR_KIND_OFFSET
Definition: parse_node.h:63
@ EXPR_KIND_JOIN_ON
Definition: parse_node.h:42
@ EXPR_KIND_HAVING
Definition: parse_node.h:47
@ EXPR_KIND_INSERT_TARGET
Definition: parse_node.h:55
@ EXPR_KIND_ALTER_COL_TRANSFORM
Definition: parse_node.h:75
@ EXPR_KIND_LIMIT
Definition: parse_node.h:62
@ EXPR_KIND_WHERE
Definition: parse_node.h:46
@ EXPR_KIND_UPDATE_TARGET
Definition: parse_node.h:57
@ EXPR_KIND_SELECT_TARGET
Definition: parse_node.h:54
@ EXPR_KIND_RETURNING
Definition: parse_node.h:64
@ EXPR_KIND_GENERATED_COLUMN
Definition: parse_node.h:83
@ EXPR_KIND_NONE
Definition: parse_node.h:40
@ EXPR_KIND_CALL_ARGUMENT
Definition: parse_node.h:81
@ EXPR_KIND_GROUP_BY
Definition: parse_node.h:59
@ EXPR_KIND_OTHER
Definition: parse_node.h:41
@ EXPR_KIND_FROM_FUNCTION
Definition: parse_node.h:45
@ EXPR_KIND_TRIGGER_WHEN
Definition: parse_node.h:77
@ EXPR_KIND_FILTER
Definition: parse_node.h:48
@ EXPR_KIND_UPDATE_SOURCE
Definition: parse_node.h:56
@ EXPR_KIND_CHECK_CONSTRAINT
Definition: parse_node.h:68
@ EXPR_KIND_WINDOW_PARTITION
Definition: parse_node.h:49
@ EXPR_KIND_CYCLE_MARK
Definition: parse_node.h:84
@ EXPR_KIND_WINDOW_FRAME_ROWS
Definition: parse_node.h:52
@ EXPR_KIND_WINDOW_ORDER
Definition: parse_node.h:50
@ EXPR_KIND_VALUES_SINGLE
Definition: parse_node.h:67

Function Documentation

◆ cancel_parser_errposition_callback()

void cancel_parser_errposition_callback ( ParseCallbackState pcbstate)

◆ free_parsestate()

void free_parsestate ( ParseState pstate)

Definition at line 72 of file parse_node.c.

73 {
74  /*
75  * Check that we did not produce too many resnos; at the very least we
76  * cannot allow more than 2^16, since that would exceed the range of a
77  * AttrNumber. It seems safest to use MaxTupleAttributeNumber.
78  */
79  if (pstate->p_next_resno - 1 > MaxTupleAttributeNumber)
80  ereport(ERROR,
81  (errcode(ERRCODE_TOO_MANY_COLUMNS),
82  errmsg("target lists can have at most %d entries",
84 
85  if (pstate->p_target_relation != NULL)
87 
88  pfree(pstate);
89 }
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
#define MaxTupleAttributeNumber
Definition: htup_details.h:34
#define NoLock
Definition: lockdefs.h:34
void pfree(void *pointer)
Definition: mcxt.c:1521
int p_next_resno
Definition: parse_node.h:231
Relation p_target_relation
Definition: parse_node.h:225
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126

References ereport, errcode(), errmsg(), ERROR, MaxTupleAttributeNumber, NoLock, ParseState::p_next_resno, ParseState::p_target_relation, pfree(), and table_close().

Referenced by AlterPolicy(), CreatePolicy(), CreateTriggerFiringOn(), inline_function(), interpret_AS_clause(), parse_analyze_fixedparams(), parse_analyze_varparams(), parse_analyze_withcb(), parse_sub_analyze(), standard_ProcessUtility(), transformIndexStmt(), transformInsertStmt(), transformJsonArrayQueryConstructor(), TransformPubWhereClauses(), transformRuleStmt(), and transformStatsStmt().

◆ make_const()

Const* make_const ( ParseState pstate,
A_Const aconst 
)

Definition at line 347 of file parse_node.c.

348 {
349  Const *con;
350  Datum val;
351  Oid typeid;
352  int typelen;
353  bool typebyval;
354  ParseCallbackState pcbstate;
355 
356  if (aconst->isnull)
357  {
358  /* return a null const */
359  con = makeConst(UNKNOWNOID,
360  -1,
361  InvalidOid,
362  -2,
363  (Datum) 0,
364  true,
365  false);
366  con->location = aconst->location;
367  return con;
368  }
369 
370  switch (nodeTag(&aconst->val))
371  {
372  case T_Integer:
373  val = Int32GetDatum(intVal(&aconst->val));
374 
375  typeid = INT4OID;
376  typelen = sizeof(int32);
377  typebyval = true;
378  break;
379 
380  case T_Float:
381  {
382  /* could be an oversize integer as well as a float ... */
383 
384  ErrorSaveContext escontext = {T_ErrorSaveContext};
385  int64 val64;
386 
387  val64 = pg_strtoint64_safe(aconst->val.fval.fval, (Node *) &escontext);
388  if (!escontext.error_occurred)
389  {
390  /*
391  * It might actually fit in int32. Probably only INT_MIN
392  * can occur, but we'll code the test generally just to be
393  * sure.
394  */
395  int32 val32 = (int32) val64;
396 
397  if (val64 == (int64) val32)
398  {
399  val = Int32GetDatum(val32);
400 
401  typeid = INT4OID;
402  typelen = sizeof(int32);
403  typebyval = true;
404  }
405  else
406  {
407  val = Int64GetDatum(val64);
408 
409  typeid = INT8OID;
410  typelen = sizeof(int64);
411  typebyval = FLOAT8PASSBYVAL; /* int8 and float8 alike */
412  }
413  }
414  else
415  {
416  /* arrange to report location if numeric_in() fails */
417  setup_parser_errposition_callback(&pcbstate, pstate, aconst->location);
419  CStringGetDatum(aconst->val.fval.fval),
421  Int32GetDatum(-1));
423 
424  typeid = NUMERICOID;
425  typelen = -1; /* variable len */
426  typebyval = false;
427  }
428  break;
429  }
430 
431  case T_Boolean:
432  val = BoolGetDatum(boolVal(&aconst->val));
433 
434  typeid = BOOLOID;
435  typelen = 1;
436  typebyval = true;
437  break;
438 
439  case T_String:
440 
441  /*
442  * We assume here that UNKNOWN's internal representation is the
443  * same as CSTRING
444  */
445  val = CStringGetDatum(strVal(&aconst->val));
446 
447  typeid = UNKNOWNOID; /* will be coerced later */
448  typelen = -2; /* cstring-style varwidth type */
449  typebyval = false;
450  break;
451 
452  case T_BitString:
453  /* arrange to report location if bit_in() fails */
454  setup_parser_errposition_callback(&pcbstate, pstate, aconst->location);
456  CStringGetDatum(aconst->val.bsval.bsval),
458  Int32GetDatum(-1));
460  typeid = BITOID;
461  typelen = -1;
462  typebyval = false;
463  break;
464 
465  default:
466  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(&aconst->val));
467  return NULL; /* keep compiler quiet */
468  }
469 
470  con = makeConst(typeid,
471  -1, /* typmod -1 is OK for all cases */
472  InvalidOid, /* all cases are uncollatable types */
473  typelen,
474  val,
475  false,
476  typebyval);
477  con->location = aconst->location;
478 
479  return con;
480 }
Datum numeric_in(PG_FUNCTION_ARGS)
Definition: numeric.c:636
signed int int32
Definition: c.h:508
#define FLOAT8PASSBYVAL
Definition: c.h:638
#define elog(elevel,...)
Definition: elog.h:225
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1807
#define DirectFunctionCall3(func, arg1, arg2, arg3)
Definition: fmgr.h:645
long val
Definition: informix.c:689
Const * makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
Definition: makefuncs.c:301
#define nodeTag(nodeptr)
Definition: nodes.h:133
int64 pg_strtoint64_safe(const char *s, Node *escontext)
Definition: numutils.c:650
void cancel_parser_errposition_callback(ParseCallbackState *pcbstate)
Definition: parse_node.c:156
void setup_parser_errposition_callback(ParseCallbackState *pcbstate, ParseState *pstate, int location)
Definition: parse_node.c:140
uintptr_t Datum
Definition: postgres.h:64
static Datum BoolGetDatum(bool X)
Definition: postgres.h:102
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
static Datum CStringGetDatum(const char *X)
Definition: postgres.h:350
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:212
#define InvalidOid
Definition: postgres_ext.h:36
unsigned int Oid
Definition: postgres_ext.h:31
bool isnull
Definition: parsenodes.h:365
union ValUnion val
Definition: parsenodes.h:364
ParseLoc location
Definition: parsenodes.h:366
char * bsval
Definition: value.h:76
bool error_occurred
Definition: miscnodes.h:47
char * fval
Definition: value.h:52
Definition: nodes.h:129
BitString bsval
Definition: parsenodes.h:356
Float fval
Definition: parsenodes.h:353
#define boolVal(v)
Definition: value.h:81
#define intVal(v)
Definition: value.h:79
#define strVal(v)
Definition: value.h:82
Datum bit_in(PG_FUNCTION_ARGS)
Definition: varbit.c:147

References bit_in(), BoolGetDatum(), boolVal, ValUnion::bsval, BitString::bsval, cancel_parser_errposition_callback(), CStringGetDatum(), DirectFunctionCall3, elog, ERROR, ErrorSaveContext::error_occurred, FLOAT8PASSBYVAL, ValUnion::fval, Float::fval, Int32GetDatum(), Int64GetDatum(), intVal, InvalidOid, A_Const::isnull, A_Const::location, makeConst(), nodeTag, numeric_in(), ObjectIdGetDatum(), pg_strtoint64_safe(), setup_parser_errposition_callback(), strVal, A_Const::val, and val.

Referenced by transformExprRecurse().

◆ make_parsestate()

ParseState* make_parsestate ( ParseState parentParseState)

Definition at line 39 of file parse_node.c.

40 {
41  ParseState *pstate;
42 
43  pstate = palloc0(sizeof(ParseState));
44 
45  pstate->parentParseState = parentParseState;
46 
47  /* Fill in fields that don't start at null/false/zero */
48  pstate->p_next_resno = 1;
49  pstate->p_resolve_unknowns = true;
50 
51  if (parentParseState)
52  {
53  pstate->p_sourcetext = parentParseState->p_sourcetext;
54  /* all hooks are copied from parent */
55  pstate->p_pre_columnref_hook = parentParseState->p_pre_columnref_hook;
56  pstate->p_post_columnref_hook = parentParseState->p_post_columnref_hook;
57  pstate->p_paramref_hook = parentParseState->p_paramref_hook;
58  pstate->p_coerce_param_hook = parentParseState->p_coerce_param_hook;
59  pstate->p_ref_hook_state = parentParseState->p_ref_hook_state;
60  /* query environment stays in context for the whole parse analysis */
61  pstate->p_queryEnv = parentParseState->p_queryEnv;
62  }
63 
64  return pstate;
65 }
void * palloc0(Size size)
Definition: mcxt.c:1347
ParseState * parentParseState
Definition: parse_node.h:208
void * p_ref_hook_state
Definition: parse_node.h:258
ParseParamRefHook p_paramref_hook
Definition: parse_node.h:256
PreParseColumnRefHook p_pre_columnref_hook
Definition: parse_node.h:254
QueryEnvironment * p_queryEnv
Definition: parse_node.h:239
const char * p_sourcetext
Definition: parse_node.h:209
bool p_resolve_unknowns
Definition: parse_node.h:236
CoerceParamHook p_coerce_param_hook
Definition: parse_node.h:257
PostParseColumnRefHook p_post_columnref_hook
Definition: parse_node.h:255

References ParseState::p_coerce_param_hook, ParseState::p_next_resno, ParseState::p_paramref_hook, ParseState::p_post_columnref_hook, ParseState::p_pre_columnref_hook, ParseState::p_queryEnv, ParseState::p_ref_hook_state, ParseState::p_resolve_unknowns, ParseState::p_sourcetext, palloc0(), and ParseState::parentParseState.

Referenced by AddRelationNewConstraints(), AlterDomainDefault(), AlterPolicy(), ATExecAttachPartition(), ATPrepAlterColumnType(), convert_ANY_sublink_to_join(), copy_table(), CreatePolicy(), CreateTriggerFiringOn(), DefineDomain(), DefineRelation(), domainAddCheckConstraint(), ExplainExecuteQuery(), inline_function(), interpret_AS_clause(), parse_analyze_fixedparams(), parse_analyze_varparams(), parse_analyze_withcb(), parse_sub_analyze(), rewriteTargetView(), standard_ProcessUtility(), test_rls_hooks_permissive(), test_rls_hooks_restrictive(), transformAlterTableStmt(), transformCreateStmt(), transformIndexStmt(), transformInsertStmt(), transformJsonArrayQueryConstructor(), transformPartitionSpec(), TransformPubWhereClauses(), transformRuleStmt(), and transformStatsStmt().

◆ parser_errposition()

int parser_errposition ( ParseState pstate,
int  location 
)

Definition at line 106 of file parse_node.c.

107 {
108  int pos;
109 
110  /* No-op if location was not provided */
111  if (location < 0)
112  return 0;
113  /* Can't do anything if source text is not available */
114  if (pstate == NULL || pstate->p_sourcetext == NULL)
115  return 0;
116  /* Convert offset to character number */
117  pos = pg_mbstrlen_with_len(pstate->p_sourcetext, location) + 1;
118  /* And pass it to the ereport mechanism */
119  return errposition(pos);
120 }
int errposition(int cursorpos)
Definition: elog.c:1446
int pg_mbstrlen_with_len(const char *mbstr, int limit)
Definition: mbutils.c:1057

References errposition(), ParseState::p_sourcetext, and pg_mbstrlen_with_len().

Referenced by addRangeTableEntryForCTE(), addRangeTableEntryForFunction(), addRangeTableEntryForTableFunc(), AlterDatabase(), analyzeCTE(), analyzeCTETargetList(), array_subscript_transform(), assign_collations_walker(), assign_hypothetical_collations(), check_agg_arguments(), check_agg_arguments_walker(), check_agglevels_and_constraints(), check_lateral_ref_ok(), check_nested_generated_walker(), check_new_partition_bound(), check_parameter_resolution_walker(), check_simple_rowfilter_expr_walker(), check_srf_call_placement(), CheckDuplicateColumnOrPathNames(), checkExprIsVarFree(), checkInsertTargets(), checkJsonOutputFormat(), checkTargetlistEntrySQL92(), checkWellFormedRecursion(), checkWellFormedRecursionWalker(), cluster(), coerce_to_boolean(), coerce_to_common_type(), coerce_to_specific_type_typmod(), colNameToVar(), compatible_oper(), compute_common_attribute(), compute_function_attributes(), ComputePartitionAttrs(), createdb(), CreateTriggerFiringOn(), defGetCopyLogVerbosityChoice(), defGetCopyOnErrorChoice(), DefineCollation(), DefineType(), DropDatabase(), errorConflictingDefElem(), errorMissingColumn(), errorMissingRTE(), EvaluateParams(), ExecReindex(), ExecVacuum(), ExpandAllTables(), ExpandColumnRefStar(), ExplainQuery(), finalize_grouping_exprs_walker(), findTargetlistEntrySQL92(), fixed_paramref_hook(), generateSerialExtraStmts(), GetColumnDefCollation(), GrantRole(), hstore_subscript_transform(), init_params(), interpret_function_parameter_list(), jsonb_subscript_transform(), LookupOperName(), LookupTypeNameExtended(), LookupTypeNameOid(), make_distinct_op(), make_op(), make_row_comparison_op(), make_row_distinct_op(), make_scalar_array_op(), merge_collation_state(), op_error(), parseCheckAggregates(), ParseFuncOrColumn(), parser_coercion_errposition(), pcb_error_callback(), plpgsql_post_column_ref(), ProcessCopyOptions(), resolve_column_ref(), resolve_unique_index_expr(), scanNameSpaceForRefname(), scanNameSpaceForRelid(), scanNSItemForColumn(), scanRTEForColumn(), select_common_collation(), select_common_type(), substitute_grouped_columns_mutator(), TopologicalSort(), transformAExprNullIf(), transformAggregateCall(), transformArrayExpr(), transformAssignedExpr(), transformAssignmentIndirection(), transformAssignmentSubscripts(), transformCaseExpr(), transformCoalesceExpr(), transformCollateClause(), transformColumnDefinition(), transformColumnRef(), transformColumnType(), transformConstraintAttrs(), transformContainerSubscripts(), transformDistinctClause(), transformDistinctOnClause(), transformExprRecurse(), transformFrameOffset(), transformFromClauseItem(), transformGroupingFunc(), transformGroupingSet(), transformIndexConstraint(), transformIndirection(), transformInsertRow(), transformJsonAggConstructor(), transformJsonArrayQueryConstructor(), transformJsonBehavior(), transformJsonFuncExpr(), transformJsonParseArg(), transformJsonParseExpr(), transformJsonReturning(), transformJsonTable(), transformJsonTableColumns(), transformJsonValueExpr(), transformLockingClause(), transformMergeSupportFunc(), transformMultiAssignRef(), transformOnConflictArbiter(), transformParamRef(), transformPartitionBound(), transformPartitionBoundValue(), transformPLAssignStmt(), transformRangeFunction(), transformRangeTableFunc(), transformRangeTableSample(), transformReturningList(), transformRowExpr(), transformSelectStmt(), transformSetOperationStmt(), transformSetOperationTree(), transformSubLink(), transformTableConstraint(), transformUpdateTargetList(), transformValuesClause(), transformWindowDefinitions(), transformWindowFuncCall(), transformWithClause(), transformXmlExpr(), transformXmlSerialize(), typenameType(), typenameTypeMod(), unknown_attribute(), validateInfiniteBounds(), variable_coerce_param_hook(), and variable_paramref_hook().

◆ setup_parser_errposition_callback()

void setup_parser_errposition_callback ( ParseCallbackState pcbstate,
ParseState pstate,
int  location 
)

◆ transformContainerSubscripts()

SubscriptingRef* transformContainerSubscripts ( ParseState pstate,
Node containerBase,
Oid  containerType,
int32  containerTypMod,
List indirection,
bool  isAssignment 
)

Definition at line 243 of file parse_node.c.

249 {
250  SubscriptingRef *sbsref;
251  const SubscriptRoutines *sbsroutines;
252  Oid elementType;
253  bool isSlice = false;
254  ListCell *idx;
255 
256  /*
257  * Determine the actual container type, smashing any domain. In the
258  * assignment case the caller already did this, since it also needs to
259  * know the actual container type.
260  */
261  if (!isAssignment)
262  transformContainerType(&containerType, &containerTypMod);
263 
264  /*
265  * Verify that the container type is subscriptable, and get its support
266  * functions and typelem.
267  */
268  sbsroutines = getSubscriptingRoutines(containerType, &elementType);
269  if (!sbsroutines)
270  ereport(ERROR,
271  (errcode(ERRCODE_DATATYPE_MISMATCH),
272  errmsg("cannot subscript type %s because it does not support subscripting",
273  format_type_be(containerType)),
274  parser_errposition(pstate, exprLocation(containerBase))));
275 
276  /*
277  * Detect whether any of the indirection items are slice specifiers.
278  *
279  * A list containing only simple subscripts refers to a single container
280  * element. If any of the items are slice specifiers (lower:upper), then
281  * the subscript expression means a container slice operation.
282  */
283  foreach(idx, indirection)
284  {
286 
287  if (ai->is_slice)
288  {
289  isSlice = true;
290  break;
291  }
292  }
293 
294  /*
295  * Ready to build the SubscriptingRef node.
296  */
297  sbsref = makeNode(SubscriptingRef);
298 
299  sbsref->refcontainertype = containerType;
300  sbsref->refelemtype = elementType;
301  /* refrestype is to be set by container-specific logic */
302  sbsref->reftypmod = containerTypMod;
303  /* refcollid will be set by parse_collate.c */
304  /* refupperindexpr, reflowerindexpr are to be set by container logic */
305  sbsref->refexpr = (Expr *) containerBase;
306  sbsref->refassgnexpr = NULL; /* caller will fill if it's an assignment */
307 
308  /*
309  * Call the container-type-specific logic to transform the subscripts and
310  * determine the subscripting result type.
311  */
312  sbsroutines->transform(sbsref, indirection, pstate,
313  isSlice, isAssignment);
314 
315  /*
316  * Verify we got a valid type (this defends, for example, against someone
317  * using array_subscript_handler as typsubscript without setting typelem).
318  */
319  if (!OidIsValid(sbsref->refrestype))
320  ereport(ERROR,
321  (errcode(ERRCODE_DATATYPE_MISMATCH),
322  errmsg("cannot subscript type %s because it does not support subscripting",
323  format_type_be(containerType))));
324 
325  return sbsref;
326 }
Datum idx(PG_FUNCTION_ARGS)
Definition: _int_op.c:259
#define OidIsValid(objectId)
Definition: c.h:778
char * format_type_be(Oid type_oid)
Definition: format_type.c:343
const struct SubscriptRoutines * getSubscriptingRoutines(Oid typid, Oid *typelemp)
Definition: lsyscache.c:3130
int exprLocation(const Node *expr)
Definition: nodeFuncs.c:1380
#define makeNode(_type_)
Definition: nodes.h:155
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:106
void transformContainerType(Oid *containerType, int32 *containerTypmod)
Definition: parse_node.c:189
#define lfirst_node(type, lc)
Definition: pg_list.h:176
bool is_slice
Definition: parsenodes.h:461
SubscriptTransform transform
Definition: subscripting.h:160
Expr * refassgnexpr
Definition: primnodes.h:703
Expr * refexpr
Definition: primnodes.h:701

References ereport, errcode(), errmsg(), ERROR, exprLocation(), format_type_be(), getSubscriptingRoutines(), idx(), A_Indices::is_slice, lfirst_node, makeNode, OidIsValid, parser_errposition(), SubscriptingRef::refassgnexpr, SubscriptingRef::refexpr, SubscriptRoutines::transform, and transformContainerType().

Referenced by transformAssignmentSubscripts(), and transformIndirection().

◆ transformContainerType()

void transformContainerType ( Oid containerType,
int32 containerTypmod 
)

Definition at line 189 of file parse_node.c.

190 {
191  /*
192  * If the input is a domain, smash to base type, and extract the actual
193  * typmod to be applied to the base type. Subscripting a domain is an
194  * operation that necessarily works on the base container type, not the
195  * domain itself. (Note that we provide no method whereby the creator of a
196  * domain over a container type could hide its ability to be subscripted.)
197  */
198  *containerType = getBaseTypeAndTypmod(*containerType, containerTypmod);
199 
200  /*
201  * We treat int2vector and oidvector as though they were domains over
202  * int2[] and oid[]. This is needed because array slicing could create an
203  * array that doesn't satisfy the dimensionality constraints of the
204  * xxxvector type; so we want the result of a slice operation to be
205  * considered to be of the more general type.
206  */
207  if (*containerType == INT2VECTOROID)
208  *containerType = INT2ARRAYOID;
209  else if (*containerType == OIDVECTOROID)
210  *containerType = OIDARRAYOID;
211 }
Oid getBaseTypeAndTypmod(Oid typid, int32 *typmod)
Definition: lsyscache.c:2538

References getBaseTypeAndTypmod().

Referenced by transformAssignmentSubscripts(), and transformContainerSubscripts().