34 Var *var,
int levelsup);
37 const char *targetName,
48 bool make_target_entry);
53 int sublevels_up,
int location,
54 bool make_target_entry);
56 bool make_target_entry);
95 if (colname == NULL && !resjunk)
133 foreach(o_target, targetlist)
225 foreach(lc, exprlist)
291 foreach(l, targetlist)
296 if (restype == UNKNOWNOID)
299 restype, TEXTOID, -1,
321 foreach(l, targetlist)
343 Var *var,
int levelsup)
349 if (var == NULL || !
IsA(var,
Var))
359 tle->resorigtbl = rte->relid;
369 if (ste == NULL || ste->resjunk)
370 elog(
ERROR,
"subquery %s does not have attribute %d",
371 rte->eref->aliasname,
attnum);
372 tle->resorigtbl = ste->resorigtbl;
373 tle->resorigcol = ste->resorigcol;
405 if (cte->search_clause)
407 if (cte->cycle_clause)
415 if (ste == NULL || ste->resjunk)
416 elog(
ERROR,
"CTE %s does not have attribute %d",
417 rte->eref->aliasname,
attnum);
418 tle->resorigtbl = ste->resorigtbl;
419 tle->resorigcol = ste->resorigcol;
481 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
482 errmsg(
"cannot assign to system column \"%s\"",
503 def->typeMod = attrtypmod;
504 def->collation = attrcollation;
509 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
510 errmsg(
"cannot set an array element to DEFAULT"),
514 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
515 errmsg(
"cannot set a subfield to DEFAULT"),
551 attrtype, attrtypmod, attrcollation, 0);
554 colVar = (
Node *) var;
582 attrtype, attrtypmod,
588 (
errcode(ERRCODE_DATATYPE_MISMATCH),
589 errmsg(
"column \"%s\" is of type %s"
590 " but expression is of type %s",
594 errhint(
"You will need to rewrite or cast the expression."),
644 tle->resname = colname;
687 const char *targetName,
688 bool targetIsSubscripting,
702 if (indirection_cell && !basenode)
713 ctest->
typeId = targetTypeId;
714 ctest->typeMod = targetTypMod;
715 ctest->collation = targetCollation;
716 basenode = (
Node *) ctest;
729 subscripts =
lappend(subscripts, n);
733 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
734 errmsg(
"row expansion via \"*\" is not supported here"),
774 baseTypeMod = targetTypMod;
780 (
errcode(ERRCODE_DATATYPE_MISMATCH),
781 errmsg(
"cannot assign to field \"%s\" of column \"%s\" because its type %s is not a composite type",
789 (
errcode(ERRCODE_UNDEFINED_COLUMN),
790 errmsg(
"cannot assign to field \"%s\" of column \"%s\" because there is no such column in data type %s",
796 (
errcode(ERRCODE_UNDEFINED_COLUMN),
797 errmsg(
"cannot assign to system column \"%s\"",
802 &fieldTypeId, &fieldTypMod, &fieldCollation);
820 fstore->
arg = (
Expr *) basenode;
823 fstore->resulttype = baseTypeId;
835 if (baseTypeId != targetTypeId)
837 baseTypeId, baseTypeMod,
844 return (
Node *) fstore;
870 targetTypeId, targetTypMod,
876 if (targetIsSubscripting)
878 (
errcode(ERRCODE_DATATYPE_MISMATCH),
879 errmsg(
"subscripted assignment to \"%s\" requires type %s"
880 " but expression is of type %s",
884 errhint(
"You will need to rewrite or cast the expression."),
888 (
errcode(ERRCODE_DATATYPE_MISMATCH),
889 errmsg(
"subfield \"%s\" is of type %s"
890 " but expression is of type %s",
894 errhint(
"You will need to rewrite or cast the expression."),
907 const char *targetName,
921 int32 containerTypMod;
929 containerType = targetTypeId;
930 containerTypMod = targetTypMod;
941 typeNeeded = sbsref->refrestype;
942 typmodNeeded = sbsref->reftypmod;
951 if (containerType == targetTypeId)
952 collationNeeded = targetCollation;
975 sbsref->refrestype = containerType;
976 sbsref->reftypmod = containerTypMod;
978 result = (
Node *) sbsref;
986 if (containerType != targetTypeId)
992 targetTypeId, targetTypMod,
999 (
errcode(ERRCODE_CANNOT_COERCE),
1000 errmsg(
"cannot cast type %s to %s",
1030 for (
i = 0;
i < numcol;
i++)
1037 if (attr->attisdropped)
1068 (
errcode(ERRCODE_UNDEFINED_COLUMN),
1069 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
1084 (
errcode(ERRCODE_DUPLICATE_COLUMN),
1085 errmsg(
"column \"%s\" specified more than once",
1095 (
errcode(ERRCODE_DUPLICATE_COLUMN),
1096 errmsg(
"column \"%s\" specified more than once",
1123 bool make_target_entry)
1138 Assert(make_target_entry);
1157 char *nspname = NULL;
1166 } crserr = CRSERR_NO_RTE;
1205 crserr = CRSERR_WRONG_DB;
1216 crserr = CRSERR_TOO_MANY;
1234 (
Node *) (nsitem ? nsitem->
p_rte : NULL));
1239 (
errcode(ERRCODE_AMBIGUOUS_COLUMN),
1240 errmsg(
"column reference \"%s\" is ambiguous",
1258 case CRSERR_WRONG_DB:
1260 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1261 errmsg(
"cross-database references are not implemented: %s",
1265 case CRSERR_TOO_MANY:
1267 (
errcode(ERRCODE_SYNTAX_ERROR),
1268 errmsg(
"improper qualified name (too many dotted names): %s",
1298 bool found_table =
false;
1328 (
errcode(ERRCODE_SYNTAX_ERROR),
1329 errmsg(
"SELECT * with no tables specified is not valid"),
1375 int sublevels_up,
int location,
bool make_target_entry)
1377 if (make_target_entry)
1401 Assert(perminfo != NULL);
1426 bool make_target_entry)
1466 ((
Var *) expr)->vartype == RECORDOID)
1473 numAttrs = tupleDesc->
natts;
1474 for (
i = 0;
i < numAttrs;
i++)
1479 if (att->attisdropped)
1485 fselect->resulttype = att->atttypid;
1486 fselect->resulttypmod = att->atttypmod;
1488 fselect->resultcollid = att->attcollation;
1490 if (make_target_entry)
1502 result =
lappend(result, fselect);
1531 Assert(var->vartype == RECORDOID);
1571 Assert(lname == NULL && lvar == NULL);
1576 expr = (
Node *) var;
1597 if (ste == NULL || ste->resjunk)
1598 elog(
ERROR,
"subquery %s does not have attribute %d",
1599 rte->eref->aliasname,
attnum);
1615 for (levelsup = 0; levelsup < netlevelsup; levelsup++)
1651 if (!rte->self_reference)
1657 if (ste == NULL || ste->resjunk)
1658 elog(
ERROR,
"CTE %s does not have attribute %d",
1659 rte->eref->aliasname,
attnum);
1766 foreach(l, ((
ColumnRef *) node)->fields)
1780 case T_A_Indirection:
1787 foreach(l,
ind->indirection)
1818 if (((
TypeCast *) node)->typeName != NULL)
1825 case T_CollateClause:
1827 case T_GroupingFunc:
1831 case T_MergeSupportFunc:
1833 *
name =
"merge_action";
1836 switch (((
SubLink *) node)->subLinkType)
1863 *
name = te->resname;
1895 case T_CoalesceExpr:
1911 case T_SQLValueFunction:
1916 *
name =
"current_date";
1920 *
name =
"current_time";
1924 *
name =
"current_timestamp";
1928 *
name =
"localtime";
1932 *
name =
"localtimestamp";
1935 *
name =
"current_role";
1938 *
name =
"current_user";
1944 *
name =
"session_user";
1947 *
name =
"current_catalog";
1950 *
name =
"current_schema";
1956 switch (((
XmlExpr *) node)->op)
1959 *
name =
"xmlconcat";
1962 *
name =
"xmlelement";
1965 *
name =
"xmlforest";
1977 *
name =
"xmlserialize";
1984 case T_XmlSerialize:
1986 *
name =
"xmlserialize";
1988 case T_JsonParseExpr:
1992 case T_JsonScalarExpr:
1994 *
name =
"json_scalar";
1996 case T_JsonSerializeExpr:
1998 *
name =
"json_serialize";
2000 case T_JsonObjectConstructor:
2002 *
name =
"json_object";
2004 case T_JsonArrayConstructor:
2005 case T_JsonArrayQueryConstructor:
2007 *
name =
"json_array";
2009 case T_JsonObjectAgg:
2011 *
name =
"json_objectagg";
2013 case T_JsonArrayAgg:
2015 *
name =
"json_arrayagg";
2017 case T_JsonFuncExpr:
2022 *
name =
"json_exists";
2025 *
name =
"json_query";
2028 *
name =
"json_value";
2032 elog(
ERROR,
"unrecognized JsonExpr op: %d",
#define InvalidAttrNumber
bool bms_is_member(int x, const Bitmapset *a)
Bitmapset * bms_add_member(Bitmapset *a, int x)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
TupleDesc get_expr_result_tupdesc(Node *expr, bool noError)
Assert(PointerIsAligned(start, uint64))
if(TABLE==NULL||TABLE_index==NULL)
List * lappend(List *list, void *datum)
List * list_concat(List *list1, const List *list2)
List * lappend_int(List *list, int datum)
List * list_truncate(List *list, int new_size)
AttrNumber get_attnum(Oid relid, const char *attname)
char * get_database_name(Oid dbid)
Oid get_typcollation(Oid typid)
Oid getBaseTypeAndTypmod(Oid typid, int32 *typmod)
void get_atttypetypmodcoll(Oid relid, AttrNumber attnum, Oid *typid, int32 *typmod, Oid *collid)
Var * makeVar(int varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
Const * makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid)
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
char * pstrdup(const char *in)
char * NameListToString(const List *names)
Oid exprType(const Node *expr)
int32 exprTypmod(const Node *expr)
Oid exprCollation(const Node *expr)
int exprLocation(const Node *expr)
#define IsA(nodeptr, _type_)
Node * coerce_to_domain(Node *arg, Oid baseTypeId, int32 baseTypeMod, Oid typeId, CoercionContext ccontext, CoercionForm cformat, int location, bool hideInputCoercion)
Node * coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId, int32 targetTypeMod, CoercionContext ccontext, CoercionForm cformat, int location)
Node * coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype, Oid targettype, int32 targettypmod, CoercionContext ccontext, CoercionForm cformat, int location)
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
int parser_errposition(ParseState *pstate, int location)
SubscriptingRef * transformContainerSubscripts(ParseState *pstate, Node *containerBase, Oid containerType, int32 containerTypMod, List *indirection, bool isAssignment)
void transformContainerType(Oid *containerType, int32 *containerTypmod)
@ EXPR_KIND_UPDATE_TARGET
@ EXPR_KIND_UPDATE_SOURCE
CommonTableExpr * GetCTEForRTE(ParseState *pstate, RangeTblEntry *rte, int rtelevelsup)
void markVarForSelectPriv(ParseState *pstate, Var *var)
void errorMissingRTE(ParseState *pstate, RangeVar *relation)
TargetEntry * get_tle_by_resno(List *tlist, AttrNumber resno)
List * expandNSItemVars(ParseState *pstate, ParseNamespaceItem *nsitem, int sublevels_up, int location, List **colnames)
void expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up, VarReturningType returning_type, int location, bool include_dropped, List **colnames, List **colvars)
ParseNamespaceItem * GetNSItemByRangeTablePosn(ParseState *pstate, int varno, int sublevels_up)
Oid attnumTypeId(Relation rd, int attid)
List * expandNSItemAttrs(ParseState *pstate, ParseNamespaceItem *nsitem, int sublevels_up, bool require_col_privs, int location)
ParseNamespaceItem * refnameNamespaceItem(ParseState *pstate, const char *schemaname, const char *refname, int location, int *sublevels_up)
RangeTblEntry * GetRTEByRangeTablePosn(ParseState *pstate, int varno, int sublevels_up)
int attnameAttNum(Relation rd, const char *attname, bool sysColOK)
TargetEntry * transformTargetEntry(ParseState *pstate, Node *node, Node *expr, ParseExprKind exprKind, char *colname, bool resjunk)
static List * ExpandColumnRefStar(ParseState *pstate, ColumnRef *cref, bool make_target_entry)
Expr * transformAssignedExpr(ParseState *pstate, Expr *expr, ParseExprKind exprKind, const char *colname, int attrno, List *indirection, int location)
static int FigureColnameInternal(Node *node, char **name)
List * transformExpressionList(ParseState *pstate, List *exprlist, ParseExprKind exprKind, bool allowDefault)
static void markTargetListOrigin(ParseState *pstate, TargetEntry *tle, Var *var, int levelsup)
char * FigureColname(Node *node)
static List * ExpandSingleTable(ParseState *pstate, ParseNamespaceItem *nsitem, int sublevels_up, int location, bool make_target_entry)
char * FigureIndexColname(Node *node)
static Node * transformAssignmentSubscripts(ParseState *pstate, Node *basenode, const char *targetName, Oid targetTypeId, int32 targetTypMod, Oid targetCollation, List *subscripts, List *indirection, ListCell *next_indirection, Node *rhs, CoercionContext ccontext, int location)
static List * ExpandRowReference(ParseState *pstate, Node *expr, bool make_target_entry)
Node * transformAssignmentIndirection(ParseState *pstate, Node *basenode, const char *targetName, bool targetIsSubscripting, Oid targetTypeId, int32 targetTypMod, Oid targetCollation, List *indirection, ListCell *indirection_cell, Node *rhs, CoercionContext ccontext, int location)
void updateTargetListEntry(ParseState *pstate, TargetEntry *tle, char *colname, int attrno, List *indirection, int location)
List * transformTargetList(ParseState *pstate, List *targetlist, ParseExprKind exprKind)
void resolveTargetListUnknowns(ParseState *pstate, List *targetlist)
void markTargetListOrigins(ParseState *pstate, List *targetlist)
static List * ExpandIndirectionStar(ParseState *pstate, A_Indirection *ind, bool make_target_entry, ParseExprKind exprKind)
static List * ExpandAllTables(ParseState *pstate, int location)
List * checkInsertTargets(ParseState *pstate, List *cols, List **attrnos)
TupleDesc expandRecordVariable(ParseState *pstate, Var *var, int levelsup)
Oid typeidTypeRelid(Oid type_id)
#define GetCTETargetList(cte)
FormData_pg_attribute * Form_pg_attribute
static int list_length(const List *l)
#define forboth(cell1, list1, cell2, list2)
#define for_each_cell(cell, lst, initcell)
static void * list_nth(const List *list, int n)
static ListCell * list_head(const List *l)
static ListCell * lnext(const List *l, const ListCell *c)
#define list_make1_int(x1)
@ SVFOP_CURRENT_TIMESTAMP
@ SVFOP_CURRENT_TIMESTAMP_N
#define RelationGetNumberOfAttributes(relation)
#define RelationGetRelationName(relation)
RTEPermissionInfo * p_perminfo
ParseState * parentParseState
ParseNamespaceItem * p_target_nsitem
ParseExprKind p_expr_kind
List * p_multiassign_exprs
PreParseColumnRefHook p_pre_columnref_hook
Relation p_target_relation
PostParseColumnRefHook p_post_columnref_hook
VarReturningType varreturningtype
TupleDesc CreateTemplateTupleDesc(int natts)
void TupleDescInitEntryCollation(TupleDesc desc, AttrNumber attributeNumber, Oid collationid)
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)