35 Var *var,
int levelsup);
38 const char *targetName,
49 bool make_target_entry);
54 int sublevels_up,
int location,
55 bool make_target_entry);
57 bool make_target_entry);
96 if (colname == NULL && !resjunk)
134 foreach(o_target, targetlist)
226 foreach(lc, exprlist)
292 foreach(l, targetlist)
297 if (restype == UNKNOWNOID)
300 restype, TEXTOID, -1,
322 foreach(l, targetlist)
344 Var *var,
int levelsup)
350 if (var == NULL || !
IsA(var,
Var))
360 tle->resorigtbl = rte->
relid;
370 if (ste == NULL || ste->resjunk)
371 elog(
ERROR,
"subquery %s does not have attribute %d",
372 rte->eref->aliasname,
attnum);
373 tle->resorigtbl = ste->resorigtbl;
374 tle->resorigcol = ste->resorigcol;
406 if (cte->search_clause)
408 if (cte->cycle_clause)
416 if (ste == NULL || ste->resjunk)
417 elog(
ERROR,
"CTE %s does not have attribute %d",
418 rte->eref->aliasname,
attnum);
419 tle->resorigtbl = ste->resorigtbl;
420 tle->resorigcol = ste->resorigcol;
482 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
483 errmsg(
"cannot assign to system column \"%s\"",
504 def->typeMod = attrtypmod;
505 def->collation = attrcollation;
510 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
511 errmsg(
"cannot set an array element to DEFAULT"),
515 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
516 errmsg(
"cannot set a subfield to DEFAULT"),
552 attrtype, attrtypmod, attrcollation, 0);
555 colVar = (
Node *) var;
583 attrtype, attrtypmod,
589 (
errcode(ERRCODE_DATATYPE_MISMATCH),
590 errmsg(
"column \"%s\" is of type %s"
591 " but expression is of type %s",
595 errhint(
"You will need to rewrite or cast the expression."),
645 tle->resname = colname;
688 const char *targetName,
689 bool targetIsSubscripting,
703 if (indirection_cell && !basenode)
714 ctest->
typeId = targetTypeId;
715 ctest->typeMod = targetTypMod;
716 ctest->collation = targetCollation;
717 basenode = (
Node *) ctest;
730 subscripts =
lappend(subscripts, n);
734 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
735 errmsg(
"row expansion via \"*\" is not supported here"),
775 baseTypeMod = targetTypMod;
781 (
errcode(ERRCODE_DATATYPE_MISMATCH),
782 errmsg(
"cannot assign to field \"%s\" of column \"%s\" because its type %s is not a composite type",
790 (
errcode(ERRCODE_UNDEFINED_COLUMN),
791 errmsg(
"cannot assign to field \"%s\" of column \"%s\" because there is no such column in data type %s",
797 (
errcode(ERRCODE_UNDEFINED_COLUMN),
798 errmsg(
"cannot assign to system column \"%s\"",
803 &fieldTypeId, &fieldTypMod, &fieldCollation);
821 fstore->
arg = (
Expr *) basenode;
824 fstore->resulttype = baseTypeId;
836 if (baseTypeId != targetTypeId)
838 baseTypeId, baseTypeMod,
845 return (
Node *) fstore;
871 targetTypeId, targetTypMod,
877 if (targetIsSubscripting)
879 (
errcode(ERRCODE_DATATYPE_MISMATCH),
880 errmsg(
"subscripted assignment to \"%s\" requires type %s"
881 " but expression is of type %s",
885 errhint(
"You will need to rewrite or cast the expression."),
889 (
errcode(ERRCODE_DATATYPE_MISMATCH),
890 errmsg(
"subfield \"%s\" is of type %s"
891 " but expression is of type %s",
895 errhint(
"You will need to rewrite or cast the expression."),
908 const char *targetName,
922 int32 containerTypMod;
930 containerType = targetTypeId;
931 containerTypMod = targetTypMod;
942 typeNeeded = sbsref->refrestype;
943 typmodNeeded = sbsref->reftypmod;
952 if (containerType == targetTypeId)
953 collationNeeded = targetCollation;
976 sbsref->refrestype = containerType;
977 sbsref->reftypmod = containerTypMod;
979 result = (
Node *) sbsref;
987 if (containerType != targetTypeId)
993 targetTypeId, targetTypMod,
1000 (
errcode(ERRCODE_CANNOT_COERCE),
1001 errmsg(
"cannot cast type %s to %s",
1031 for (
i = 0;
i < numcol;
i++)
1038 if (attr->attisdropped)
1069 (
errcode(ERRCODE_UNDEFINED_COLUMN),
1070 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
1085 (
errcode(ERRCODE_DUPLICATE_COLUMN),
1086 errmsg(
"column \"%s\" specified more than once",
1096 (
errcode(ERRCODE_DUPLICATE_COLUMN),
1097 errmsg(
"column \"%s\" specified more than once",
1124 bool make_target_entry)
1139 Assert(make_target_entry);
1158 char *nspname = NULL;
1167 } crserr = CRSERR_NO_RTE;
1206 crserr = CRSERR_WRONG_DB;
1217 crserr = CRSERR_TOO_MANY;
1235 (
Node *) (nsitem ? nsitem->
p_rte : NULL));
1240 (
errcode(ERRCODE_AMBIGUOUS_COLUMN),
1241 errmsg(
"column reference \"%s\" is ambiguous",
1259 case CRSERR_WRONG_DB:
1261 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1262 errmsg(
"cross-database references are not implemented: %s",
1266 case CRSERR_TOO_MANY:
1268 (
errcode(ERRCODE_SYNTAX_ERROR),
1269 errmsg(
"improper qualified name (too many dotted names): %s",
1299 bool found_table =
false;
1329 (
errcode(ERRCODE_SYNTAX_ERROR),
1330 errmsg(
"SELECT * with no tables specified is not valid"),
1376 int sublevels_up,
int location,
bool make_target_entry)
1378 if (make_target_entry)
1402 Assert(perminfo != NULL);
1427 bool make_target_entry)
1467 ((
Var *) expr)->vartype == RECORDOID)
1474 numAttrs = tupleDesc->
natts;
1475 for (
i = 0;
i < numAttrs;
i++)
1480 if (att->attisdropped)
1486 fselect->resulttype = att->atttypid;
1487 fselect->resulttypmod = att->atttypmod;
1489 fselect->resultcollid = att->attcollation;
1491 if (make_target_entry)
1503 result =
lappend(result, fselect);
1532 Assert(var->vartype == RECORDOID);
1572 Assert(lname == NULL && lvar == NULL);
1577 expr = (
Node *) var;
1598 if (ste == NULL || ste->resjunk)
1599 elog(
ERROR,
"subquery %s does not have attribute %d",
1600 rte->eref->aliasname,
attnum);
1616 for (levelsup = 0; levelsup < netlevelsup; levelsup++)
1652 if (!rte->self_reference)
1658 if (ste == NULL || ste->resjunk)
1659 elog(
ERROR,
"CTE %s does not have attribute %d",
1660 rte->eref->aliasname,
attnum);
1767 foreach(l, ((
ColumnRef *) node)->fields)
1781 case T_A_Indirection:
1788 foreach(l,
ind->indirection)
1819 if (((
TypeCast *) node)->typeName != NULL)
1826 case T_CollateClause:
1828 case T_GroupingFunc:
1832 case T_MergeSupportFunc:
1834 *
name =
"merge_action";
1837 switch (((
SubLink *) node)->subLinkType)
1864 *
name = te->resname;
1896 case T_CoalesceExpr:
1912 case T_SQLValueFunction:
1917 *
name =
"current_date";
1921 *
name =
"current_time";
1925 *
name =
"current_timestamp";
1929 *
name =
"localtime";
1933 *
name =
"localtimestamp";
1936 *
name =
"current_role";
1939 *
name =
"current_user";
1945 *
name =
"session_user";
1948 *
name =
"current_catalog";
1951 *
name =
"current_schema";
1957 switch (((
XmlExpr *) node)->op)
1960 *
name =
"xmlconcat";
1963 *
name =
"xmlelement";
1966 *
name =
"xmlforest";
1978 *
name =
"xmlserialize";
1985 case T_XmlSerialize:
1987 *
name =
"xmlserialize";
1989 case T_JsonParseExpr:
1993 case T_JsonScalarExpr:
1995 *
name =
"json_scalar";
1997 case T_JsonSerializeExpr:
1999 *
name =
"json_serialize";
2001 case T_JsonObjectConstructor:
2003 *
name =
"json_object";
2005 case T_JsonArrayConstructor:
2006 case T_JsonArrayQueryConstructor:
2008 *
name =
"json_array";
2010 case T_JsonObjectAgg:
2012 *
name =
"json_objectagg";
2014 case T_JsonArrayAgg:
2016 *
name =
"json_arrayagg";
2018 case T_JsonFuncExpr:
2023 *
name =
"json_exists";
2026 *
name =
"json_query";
2029 *
name =
"json_value";
2033 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)
#define Assert(condition)
char * get_database_name(Oid dbid)
static void PGresult * res
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)
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)
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)