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  ParseCallbackState
 

Typedefs

typedef enum ParseExprKind ParseExprKind
 
typedef struct ParseState ParseState
 
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 ParseNamespaceItem ParseNamespaceItem
 
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_GROUP_BY, EXPR_KIND_ORDER_BY,
  EXPR_KIND_DISTINCT_ON, EXPR_KIND_LIMIT, EXPR_KIND_OFFSET, EXPR_KIND_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_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
}
 

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)
 
Varmake_var (ParseState *pstate, RangeTblEntry *rte, int attrno, int location)
 
Oid transformContainerType (Oid *containerType, int32 *containerTypmod)
 
SubscriptingReftransformContainerSubscripts (ParseState *pstate, Node *containerBase, Oid containerType, Oid elementType, int32 containerTypMod, List *indirection, Node *assignFrom)
 
Constmake_const (ParseState *pstate, Value *value, int location)
 

Typedef Documentation

◆ CoerceParamHook

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

Definition at line 87 of file parse_node.h.

◆ ParseCallbackState

◆ ParseExprKind

◆ ParseNamespaceItem

◆ ParseParamRefHook

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

Definition at line 86 of file parse_node.h.

◆ ParseState

typedef struct ParseState ParseState

Definition at line 82 of file parse_node.h.

◆ PostParseColumnRefHook

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

Definition at line 85 of file parse_node.h.

◆ PreParseColumnRefHook

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

Definition at line 84 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_GROUP_BY 
EXPR_KIND_ORDER_BY 
EXPR_KIND_DISTINCT_ON 
EXPR_KIND_LIMIT 
EXPR_KIND_OFFSET 
EXPR_KIND_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_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 

Definition at line 33 of file parse_node.h.

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

Function Documentation

◆ cancel_parser_errposition_callback()

void cancel_parser_errposition_callback ( ParseCallbackState pcbstate)

◆ free_parsestate()

void free_parsestate ( ParseState pstate)

Definition at line 77 of file parse_node.c.

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

Referenced by AlterPolicy(), CreatePolicy(), CreateTrigger(), inline_function(), parse_analyze(), parse_analyze_varparams(), parse_sub_analyze(), pg_analyze_and_rewrite_params(), RemoveRoleFromObjectPolicy(), standard_ProcessUtility(), transformIndexStmt(), transformInsertStmt(), and transformRuleStmt().

78 {
79  /*
80  * Check that we did not produce too many resnos; at the very least we
81  * cannot allow more than 2^16, since that would exceed the range of a
82  * AttrNumber. It seems safest to use MaxTupleAttributeNumber.
83  */
84  if (pstate->p_next_resno - 1 > MaxTupleAttributeNumber)
85  ereport(ERROR,
86  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
87  errmsg("target lists can have at most %d entries",
89 
90  if (pstate->p_target_relation != NULL)
92 
93  pfree(pstate);
94 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
#define MaxTupleAttributeNumber
Definition: htup_details.h:33
int errcode(int sqlerrcode)
Definition: elog.c:570
void pfree(void *pointer)
Definition: mcxt.c:1031
#define ERROR
Definition: elog.h:43
#define NoLock
Definition: lockdefs.h:34
int p_next_resno
Definition: parse_node.h:192
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:784
Relation p_target_relation
Definition: parse_node.h:187

◆ make_const()

Const* make_const ( ParseState pstate,
Value value,
int  location 
)

Definition at line 477 of file parse_node.c.

References bit_in(), cancel_parser_errposition_callback(), CStringGetDatum, DirectFunctionCall3, elog, ERROR, Int32GetDatum, Int64GetDatum(), intVal, InvalidOid, Const::location, makeConst(), nodeTag, numeric_in(), ObjectIdGetDatum, scanint8(), setup_parser_errposition_callback(), strVal, T_BitString, T_Float, T_Integer, T_Null, T_String, and val.

Referenced by transformExprRecurse().

478 {
479  Const *con;
480  Datum val;
481  int64 val64;
482  Oid typeid;
483  int typelen;
484  bool typebyval;
485  ParseCallbackState pcbstate;
486 
487  switch (nodeTag(value))
488  {
489  case T_Integer:
490  val = Int32GetDatum(intVal(value));
491 
492  typeid = INT4OID;
493  typelen = sizeof(int32);
494  typebyval = true;
495  break;
496 
497  case T_Float:
498  /* could be an oversize integer as well as a float ... */
499  if (scanint8(strVal(value), true, &val64))
500  {
501  /*
502  * It might actually fit in int32. Probably only INT_MIN can
503  * occur, but we'll code the test generally just to be sure.
504  */
505  int32 val32 = (int32) val64;
506 
507  if (val64 == (int64) val32)
508  {
509  val = Int32GetDatum(val32);
510 
511  typeid = INT4OID;
512  typelen = sizeof(int32);
513  typebyval = true;
514  }
515  else
516  {
517  val = Int64GetDatum(val64);
518 
519  typeid = INT8OID;
520  typelen = sizeof(int64);
521  typebyval = FLOAT8PASSBYVAL; /* int8 and float8 alike */
522  }
523  }
524  else
525  {
526  /* arrange to report location if numeric_in() fails */
527  setup_parser_errposition_callback(&pcbstate, pstate, location);
529  CStringGetDatum(strVal(value)),
531  Int32GetDatum(-1));
533 
534  typeid = NUMERICOID;
535  typelen = -1; /* variable len */
536  typebyval = false;
537  }
538  break;
539 
540  case T_String:
541 
542  /*
543  * We assume here that UNKNOWN's internal representation is the
544  * same as CSTRING
545  */
546  val = CStringGetDatum(strVal(value));
547 
548  typeid = UNKNOWNOID; /* will be coerced later */
549  typelen = -2; /* cstring-style varwidth type */
550  typebyval = false;
551  break;
552 
553  case T_BitString:
554  /* arrange to report location if bit_in() fails */
555  setup_parser_errposition_callback(&pcbstate, pstate, location);
557  CStringGetDatum(strVal(value)),
559  Int32GetDatum(-1));
561  typeid = BITOID;
562  typelen = -1;
563  typebyval = false;
564  break;
565 
566  case T_Null:
567  /* return a null const */
568  con = makeConst(UNKNOWNOID,
569  -1,
570  InvalidOid,
571  -2,
572  (Datum) 0,
573  true,
574  false);
575  con->location = location;
576  return con;
577 
578  default:
579  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(value));
580  return NULL; /* keep compiler quiet */
581  }
582 
583  con = makeConst(typeid,
584  -1, /* typmod -1 is OK for all cases */
585  InvalidOid, /* all cases are uncollatable types */
586  typelen,
587  val,
588  false,
589  typebyval);
590  con->location = location;
591 
592  return con;
593 }
#define strVal(v)
Definition: value.h:54
unsigned int Oid
Definition: postgres_ext.h:31
Const * makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
Definition: makefuncs.c:297
signed int int32
Definition: c.h:346
void cancel_parser_errposition_callback(ParseCallbackState *pcbstate)
Definition: parse_node.c:161
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
Datum bit_in(PG_FUNCTION_ARGS)
Definition: varbit.c:146
#define CStringGetDatum(X)
Definition: postgres.h:578
Datum numeric_in(PG_FUNCTION_ARGS)
Definition: numeric.c:573
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1699
void setup_parser_errposition_callback(ParseCallbackState *pcbstate, ParseState *pstate, int location)
Definition: parse_node.c:145
#define DirectFunctionCall3(func, arg1, arg2, arg3)
Definition: fmgr.h:621
int location
Definition: primnodes.h:207
uintptr_t Datum
Definition: postgres.h:367
#define InvalidOid
Definition: postgres_ext.h:36
#define nodeTag(nodeptr)
Definition: nodes.h:530
Definition: nodes.h:292
Definition: nodes.h:289
#define Int32GetDatum(X)
Definition: postgres.h:479
#define intVal(v)
Definition: value.h:52
#define elog(elevel,...)
Definition: elog.h:226
long val
Definition: informix.c:684
bool scanint8(const char *str, bool errorOK, int64 *result)
Definition: int8.c:57

◆ make_parsestate()

ParseState* make_parsestate ( ParseState parentParseState)

Definition at line 44 of file parse_node.c.

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(), ATPrepAlterColumnType(), check_new_partition_bound(), convert_ANY_sublink_to_join(), copy_table(), CreatePolicy(), CreateTrigger(), DefineDomain(), DefineRelation(), domainAddConstraint(), EvaluateParams(), inline_function(), parse_analyze(), parse_analyze_varparams(), parse_sub_analyze(), pg_analyze_and_rewrite_params(), PrepareQuery(), RemoveRoleFromObjectPolicy(), rewriteTargetView(), standard_ProcessUtility(), test_rls_hooks_permissive(), test_rls_hooks_restrictive(), transformAlterTableStmt(), transformCreateStmt(), transformIndexStmt(), transformInsertStmt(), transformPartitionSpec(), transformRuleStmt(), and UpdateRangeTableOfViewParse().

45 {
46  ParseState *pstate;
47 
48  pstate = palloc0(sizeof(ParseState));
49 
50  pstate->parentParseState = parentParseState;
51 
52  /* Fill in fields that don't start at null/false/zero */
53  pstate->p_next_resno = 1;
54  pstate->p_resolve_unknowns = true;
55 
56  if (parentParseState)
57  {
58  pstate->p_sourcetext = parentParseState->p_sourcetext;
59  /* all hooks are copied from parent */
60  pstate->p_pre_columnref_hook = parentParseState->p_pre_columnref_hook;
61  pstate->p_post_columnref_hook = parentParseState->p_post_columnref_hook;
62  pstate->p_paramref_hook = parentParseState->p_paramref_hook;
63  pstate->p_coerce_param_hook = parentParseState->p_coerce_param_hook;
64  pstate->p_ref_hook_state = parentParseState->p_ref_hook_state;
65  /* query environment stays in context for the whole parse analysis */
66  pstate->p_queryEnv = parentParseState->p_queryEnv;
67  }
68 
69  return pstate;
70 }
QueryEnvironment * p_queryEnv
Definition: parse_node.h:200
CoerceParamHook p_coerce_param_hook
Definition: parse_node.h:218
PostParseColumnRefHook p_post_columnref_hook
Definition: parse_node.h:216
bool p_resolve_unknowns
Definition: parse_node.h:197
ParseParamRefHook p_paramref_hook
Definition: parse_node.h:217
int p_next_resno
Definition: parse_node.h:192
const char * p_sourcetext
Definition: parse_node.h:176
struct ParseState * parentParseState
Definition: parse_node.h:175
void * palloc0(Size size)
Definition: mcxt.c:955
void * p_ref_hook_state
Definition: parse_node.h:219
PreParseColumnRefHook p_pre_columnref_hook
Definition: parse_node.h:215

◆ make_var()

Var* make_var ( ParseState pstate,
RangeTblEntry rte,
int  attrno,
int  location 
)

Definition at line 189 of file parse_node.c.

References get_rte_attribute_type(), Var::location, makeVar(), and RTERangeTablePosn().

Referenced by scanRTEForColumn(), and transformAssignedExpr().

190 {
191  Var *result;
192  int vnum,
193  sublevels_up;
194  Oid vartypeid;
195  int32 type_mod;
196  Oid varcollid;
197 
198  vnum = RTERangeTablePosn(pstate, rte, &sublevels_up);
199  get_rte_attribute_type(rte, attrno, &vartypeid, &type_mod, &varcollid);
200  result = makeVar(vnum, attrno, vartypeid, type_mod, varcollid, sublevels_up);
201  result->location = location;
202  return result;
203 }
void get_rte_attribute_type(RangeTblEntry *rte, AttrNumber attnum, Oid *vartype, int32 *vartypmod, Oid *varcollid)
unsigned int Oid
Definition: postgres_ext.h:31
Definition: primnodes.h:167
signed int int32
Definition: c.h:346
int location
Definition: primnodes.h:182
Var * makeVar(Index varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
Definition: makefuncs.c:66
int RTERangeTablePosn(ParseState *pstate, RangeTblEntry *rte, int *sublevels_up)

◆ parser_errposition()

int parser_errposition ( ParseState pstate,
int  location 
)

Definition at line 111 of file parse_node.c.

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

Referenced by addRangeTableEntryForCTE(), addRangeTableEntryForFunction(), AlterDatabase(), analyzeCTE(), analyzeCTETargetList(), 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_srf_call_placement(), check_ungrouped_columns_walker(), checkExprIsVarFree(), checkInsertTargets(), checkTargetlistEntrySQL92(), checkWellFormedRecursion(), checkWellFormedRecursionWalker(), coerce_to_boolean(), coerce_to_common_type(), coerce_to_specific_type_typmod(), colNameToVar(), compatible_oper(), compute_common_attribute(), compute_function_attributes(), ComputePartitionAttrs(), createdb(), CreateExtension(), CreateRole(), CreateTrigger(), DefineCollation(), DefineType(), emit_precedence_warnings(), errorMissingColumn(), errorMissingRTE(), ExecAlterDefaultPrivilegesStmt(), ExecAlterExtensionStmt(), ExecVacuum(), ExpandAllTables(), ExpandColumnRefStar(), ExplainQuery(), finalize_grouping_exprs_walker(), findTargetlistEntrySQL92(), fixed_paramref_hook(), GetColumnDefCollation(), init_params(), 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(), parseTypeString(), pcb_error_callback(), plpgsql_post_column_ref(), ProcessCopyOptions(), resolve_column_ref(), resolve_unique_index_expr(), scanNameSpaceForRefname(), scanNameSpaceForRelid(), scanRTEForColumn(), select_common_collation(), select_common_type(), 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(), transformInsertStmt(), transformLockingClause(), transformMultiAssignRef(), transformOnConflictArbiter(), transformParamRef(), transformPartitionBound(), transformPartitionBoundValue(), transformRangeFunction(), transformRangeTableFunc(), transformRangeTableSample(), transformReturningList(), 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().

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

◆ setup_parser_errposition_callback()

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

Definition at line 145 of file parse_node.c.

References ErrorContextCallback::arg, ErrorContextCallback::callback, ParseCallbackState::errcallback, error_context_stack, ParseCallbackState::location, pcb_error_callback(), ErrorContextCallback::previous, and ParseCallbackState::pstate.

Referenced by addTargetToGroupList(), addTargetToSortList(), coerce_type(), LookupCollation(), LookupTypeNameExtended(), make_const(), make_oper_cache_key(), ParseFuncOrColumn(), parserOpenTable(), transformCreateStmt(), transformSetOperationTree(), transformTableLikeClause(), and typenameTypeMod().

147 {
148  /* Setup error traceback support for ereport() */
149  pcbstate->pstate = pstate;
150  pcbstate->location = location;
152  pcbstate->errcallback.arg = (void *) pcbstate;
154  error_context_stack = &pcbstate->errcallback;
155 }
ErrorContextCallback errcallback
Definition: parse_node.h:263
void(* callback)(void *arg)
Definition: elog.h:254
struct ErrorContextCallback * previous
Definition: elog.h:253
ErrorContextCallback * error_context_stack
Definition: elog.c:88
ParseState * pstate
Definition: parse_node.h:261
static void pcb_error_callback(void *arg)
Definition: parse_node.c:175

◆ transformContainerSubscripts()

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

Definition at line 298 of file parse_node.c.

References Assert, COERCE_IMPLICIT_CAST, coerce_to_target_type(), COERCION_ASSIGNMENT, ereport, errcode(), errhint(), errmsg(), ERROR, exprLocation(), exprType(), format_type_be(), idx(), Int32GetDatum, InvalidOid, A_Indices::is_slice, lappend(), lfirst, lfirst_node, A_Indices::lidx, makeConst(), makeNode, NIL, OidIsValid, ParseState::p_expr_kind, parser_errposition(), SubscriptingRef::refassgnexpr, SubscriptingRef::refcontainertype, SubscriptingRef::refelemtype, SubscriptingRef::refexpr, SubscriptingRef::reflowerindexpr, SubscriptingRef::reftypmod, SubscriptingRef::refupperindexpr, transformContainerType(), transformExpr(), and A_Indices::uidx.

Referenced by transformAssignmentSubscripts(), and transformIndirection().

305 {
306  bool isSlice = false;
307  List *upperIndexpr = NIL;
308  List *lowerIndexpr = NIL;
309  ListCell *idx;
310  SubscriptingRef *sbsref;
311 
312  /*
313  * Caller may or may not have bothered to determine elementType. Note
314  * that if the caller did do so, containerType/containerTypMod must be as
315  * modified by transformContainerType, ie, smash domain to base type.
316  */
317  if (!OidIsValid(elementType))
318  elementType = transformContainerType(&containerType, &containerTypMod);
319 
320  /*
321  * A list containing only simple subscripts refers to a single container
322  * element. If any of the items are slice specifiers (lower:upper), then
323  * the subscript expression means a container slice operation. In this
324  * case, we convert any non-slice items to slices by treating the single
325  * subscript as the upper bound and supplying an assumed lower bound of 1.
326  * We have to prescan the list to see if there are any slice items.
327  */
328  foreach(idx, indirection)
329  {
330  A_Indices *ai = (A_Indices *) lfirst(idx);
331 
332  if (ai->is_slice)
333  {
334  isSlice = true;
335  break;
336  }
337  }
338 
339  /*
340  * Transform the subscript expressions.
341  */
342  foreach(idx, indirection)
343  {
344  A_Indices *ai = lfirst_node(A_Indices, idx);
345  Node *subexpr;
346 
347  if (isSlice)
348  {
349  if (ai->lidx)
350  {
351  subexpr = transformExpr(pstate, ai->lidx, pstate->p_expr_kind);
352  /* If it's not int4 already, try to coerce */
353  subexpr = coerce_to_target_type(pstate,
354  subexpr, exprType(subexpr),
355  INT4OID, -1,
358  -1);
359  if (subexpr == NULL)
360  ereport(ERROR,
361  (errcode(ERRCODE_DATATYPE_MISMATCH),
362  errmsg("array subscript must have type integer"),
363  parser_errposition(pstate, exprLocation(ai->lidx))));
364  }
365  else if (!ai->is_slice)
366  {
367  /* Make a constant 1 */
368  subexpr = (Node *) makeConst(INT4OID,
369  -1,
370  InvalidOid,
371  sizeof(int32),
372  Int32GetDatum(1),
373  false,
374  true); /* pass by value */
375  }
376  else
377  {
378  /* Slice with omitted lower bound, put NULL into the list */
379  subexpr = NULL;
380  }
381  lowerIndexpr = lappend(lowerIndexpr, subexpr);
382  }
383  else
384  Assert(ai->lidx == NULL && !ai->is_slice);
385 
386  if (ai->uidx)
387  {
388  subexpr = transformExpr(pstate, ai->uidx, pstate->p_expr_kind);
389  /* If it's not int4 already, try to coerce */
390  subexpr = coerce_to_target_type(pstate,
391  subexpr, exprType(subexpr),
392  INT4OID, -1,
395  -1);
396  if (subexpr == NULL)
397  ereport(ERROR,
398  (errcode(ERRCODE_DATATYPE_MISMATCH),
399  errmsg("array subscript must have type integer"),
400  parser_errposition(pstate, exprLocation(ai->uidx))));
401  }
402  else
403  {
404  /* Slice with omitted upper bound, put NULL into the list */
405  Assert(isSlice && ai->is_slice);
406  subexpr = NULL;
407  }
408  upperIndexpr = lappend(upperIndexpr, subexpr);
409  }
410 
411  /*
412  * If doing an array store, coerce the source value to the right type.
413  * (This should agree with the coercion done by transformAssignedExpr.)
414  */
415  if (assignFrom != NULL)
416  {
417  Oid typesource = exprType(assignFrom);
418  Oid typeneeded = isSlice ? containerType : elementType;
419  Node *newFrom;
420 
421  newFrom = coerce_to_target_type(pstate,
422  assignFrom, typesource,
423  typeneeded, containerTypMod,
426  -1);
427  if (newFrom == NULL)
428  ereport(ERROR,
429  (errcode(ERRCODE_DATATYPE_MISMATCH),
430  errmsg("array assignment requires type %s"
431  " but expression is of type %s",
432  format_type_be(typeneeded),
433  format_type_be(typesource)),
434  errhint("You will need to rewrite or cast the expression."),
435  parser_errposition(pstate, exprLocation(assignFrom))));
436  assignFrom = newFrom;
437  }
438 
439  /*
440  * Ready to build the SubscriptingRef node.
441  */
443  if (assignFrom != NULL)
444  sbsref->refassgnexpr = (Expr *) assignFrom;
445 
446  sbsref->refcontainertype = containerType;
447  sbsref->refelemtype = elementType;
448  sbsref->reftypmod = containerTypMod;
449  /* refcollid will be set by parse_collate.c */
450  sbsref->refupperindexpr = upperIndexpr;
451  sbsref->reflowerindexpr = lowerIndexpr;
452  sbsref->refexpr = (Expr *) containerBase;
453  sbsref->refassgnexpr = (Expr *) assignFrom;
454 
455  return sbsref;
456 }
#define NIL
Definition: pg_list.h:65
int errhint(const char *fmt,...)
Definition: elog.c:974
int exprLocation(const Node *expr)
Definition: nodeFuncs.c:1192
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
Definition: parse_expr.c:145
Definition: nodes.h:525
int errcode(int sqlerrcode)
Definition: elog.c:570
char * format_type_be(Oid type_oid)
Definition: format_type.c:326
Datum idx(PG_FUNCTION_ARGS)
Definition: _int_op.c:264
unsigned int Oid
Definition: postgres_ext.h:31
Const * makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
Definition: makefuncs.c:297
List * refupperindexpr
Definition: primnodes.h:408
#define OidIsValid(objectId)
Definition: c.h:638
signed int int32
Definition: c.h:346
bool is_slice
Definition: parsenodes.h:382
#define ERROR
Definition: elog.h:43
Node * coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype, Oid targettype, int32 targettypmod, CoercionContext ccontext, CoercionForm cformat, int location)
Definition: parse_coerce.c:78
#define lfirst_node(type, lc)
Definition: pg_list.h:193
#define ereport(elevel, rest)
Definition: elog.h:141
List * lappend(List *list, void *datum)
Definition: list.c:321
ParseExprKind p_expr_kind
Definition: parse_node.h:191
#define InvalidOid
Definition: postgres_ext.h:36
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:732
#define lfirst(lc)
Definition: pg_list.h:190
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:111
Node * lidx
Definition: parsenodes.h:383
Expr * refassgnexpr
Definition: primnodes.h:416
#define Int32GetDatum(X)
Definition: postgres.h:479
int errmsg(const char *fmt,...)
Definition: elog.c:784
List * reflowerindexpr
Definition: primnodes.h:410
Node * uidx
Definition: parsenodes.h:384
Oid refcontainertype
Definition: primnodes.h:404
Expr * refexpr
Definition: primnodes.h:413
Definition: pg_list.h:50
Oid transformContainerType(Oid *containerType, int32 *containerTypmod)
Definition: parse_node.c:217

◆ transformContainerType()

Oid transformContainerType ( Oid containerType,
int32 containerTypmod 
)

Definition at line 217 of file parse_node.c.

References elog, ereport, errcode(), errmsg(), ERROR, format_type_be(), getBaseTypeAndTypmod(), GETSTRUCT, HeapTupleIsValid, InvalidOid, ObjectIdGetDatum, ReleaseSysCache(), SearchSysCache1(), and TYPEOID.

Referenced by transformAssignmentSubscripts(), and transformContainerSubscripts().

218 {
219  Oid origContainerType = *containerType;
220  Oid elementType;
221  HeapTuple type_tuple_container;
222  Form_pg_type type_struct_container;
223 
224  /*
225  * If the input is a domain, smash to base type, and extract the actual
226  * typmod to be applied to the base type. Subscripting a domain is an
227  * operation that necessarily works on the base container type, not the
228  * domain itself. (Note that we provide no method whereby the creator of a
229  * domain over a container type could hide its ability to be subscripted.)
230  */
231  *containerType = getBaseTypeAndTypmod(*containerType, containerTypmod);
232 
233  /*
234  * Here is an array specific code. We treat int2vector and oidvector as
235  * though they were domains over int2[] and oid[]. This is needed because
236  * array slicing could create an array that doesn't satisfy the
237  * dimensionality constraints of the xxxvector type; so we want the result
238  * of a slice operation to be considered to be of the more general type.
239  */
240  if (*containerType == INT2VECTOROID)
241  *containerType = INT2ARRAYOID;
242  else if (*containerType == OIDVECTOROID)
243  *containerType = OIDARRAYOID;
244 
245  /* Get the type tuple for the container */
246  type_tuple_container = SearchSysCache1(TYPEOID, ObjectIdGetDatum(*containerType));
247  if (!HeapTupleIsValid(type_tuple_container))
248  elog(ERROR, "cache lookup failed for type %u", *containerType);
249  type_struct_container = (Form_pg_type) GETSTRUCT(type_tuple_container);
250 
251  /* needn't check typisdefined since this will fail anyway */
252 
253  elementType = type_struct_container->typelem;
254  if (elementType == InvalidOid)
255  ereport(ERROR,
256  (errcode(ERRCODE_DATATYPE_MISMATCH),
257  errmsg("cannot subscript type %s because it is not an array",
258  format_type_be(origContainerType))));
259 
260  ReleaseSysCache(type_tuple_container);
261 
262  return elementType;
263 }
Oid getBaseTypeAndTypmod(Oid typid, int32 *typmod)
Definition: lsyscache.c:2316
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
int errcode(int sqlerrcode)
Definition: elog.c:570
char * format_type_be(Oid type_oid)
Definition: format_type.c:326
unsigned int Oid
Definition: postgres_ext.h:31
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1124
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1172
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
FormData_pg_type * Form_pg_type
Definition: pg_type.h:251
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define elog(elevel,...)
Definition: elog.h:226