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;
479 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
480 errmsg(
"cannot assign to system column \"%s\"",
501 def->typeMod = attrtypmod;
502 def->collation = attrcollation;
507 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
508 errmsg(
"cannot set an array element to DEFAULT"),
512 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
513 errmsg(
"cannot set a subfield to DEFAULT"),
549 attrtype, attrtypmod, attrcollation, 0);
552 colVar = (
Node *) var;
580 attrtype, attrtypmod,
586 (
errcode(ERRCODE_DATATYPE_MISMATCH),
587 errmsg(
"column \"%s\" is of type %s"
588 " but expression is of type %s",
592 errhint(
"You will need to rewrite or cast the expression."),
642 tle->resname = colname;
685 const char *targetName,
686 bool targetIsSubscripting,
700 if (indirection_cell && !basenode)
711 ctest->
typeId = targetTypeId;
712 ctest->typeMod = targetTypMod;
713 ctest->collation = targetCollation;
714 basenode = (
Node *) ctest;
727 subscripts =
lappend(subscripts, n);
731 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
732 errmsg(
"row expansion via \"*\" is not supported here"),
772 baseTypeMod = targetTypMod;
778 (
errcode(ERRCODE_DATATYPE_MISMATCH),
779 errmsg(
"cannot assign to field \"%s\" of column \"%s\" because its type %s is not a composite type",
787 (
errcode(ERRCODE_UNDEFINED_COLUMN),
788 errmsg(
"cannot assign to field \"%s\" of column \"%s\" because there is no such column in data type %s",
794 (
errcode(ERRCODE_UNDEFINED_COLUMN),
795 errmsg(
"cannot assign to system column \"%s\"",
800 &fieldTypeId, &fieldTypMod, &fieldCollation);
818 fstore->
arg = (
Expr *) basenode;
821 fstore->resulttype = baseTypeId;
833 if (baseTypeId != targetTypeId)
835 baseTypeId, baseTypeMod,
842 return (
Node *) fstore;
868 targetTypeId, targetTypMod,
874 if (targetIsSubscripting)
876 (
errcode(ERRCODE_DATATYPE_MISMATCH),
877 errmsg(
"subscripted assignment to \"%s\" requires type %s"
878 " but expression is of type %s",
882 errhint(
"You will need to rewrite or cast the expression."),
886 (
errcode(ERRCODE_DATATYPE_MISMATCH),
887 errmsg(
"subfield \"%s\" is of type %s"
888 " but expression is of type %s",
892 errhint(
"You will need to rewrite or cast the expression."),
905 const char *targetName,
919 int32 containerTypMod;
927 containerType = targetTypeId;
928 containerTypMod = targetTypMod;
939 typeNeeded = sbsref->refrestype;
940 typmodNeeded = sbsref->reftypmod;
949 if (containerType == targetTypeId)
950 collationNeeded = targetCollation;
973 sbsref->refrestype = containerType;
974 sbsref->reftypmod = containerTypMod;
976 result = (
Node *) sbsref;
984 if (containerType != targetTypeId)
990 targetTypeId, targetTypMod,
997 (
errcode(ERRCODE_CANNOT_COERCE),
998 errmsg(
"cannot cast type %s to %s",
1028 for (
i = 0;
i < numcol;
i++)
1035 if (attr->attisdropped)
1066 (
errcode(ERRCODE_UNDEFINED_COLUMN),
1067 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
1082 (
errcode(ERRCODE_DUPLICATE_COLUMN),
1083 errmsg(
"column \"%s\" specified more than once",
1093 (
errcode(ERRCODE_DUPLICATE_COLUMN),
1094 errmsg(
"column \"%s\" specified more than once",
1121 bool make_target_entry)
1136 Assert(make_target_entry);
1155 char *nspname = NULL;
1164 } crserr = CRSERR_NO_RTE;
1203 crserr = CRSERR_WRONG_DB;
1214 crserr = CRSERR_TOO_MANY;
1232 (
Node *) (nsitem ? nsitem->
p_rte : NULL));
1237 (
errcode(ERRCODE_AMBIGUOUS_COLUMN),
1238 errmsg(
"column reference \"%s\" is ambiguous",
1256 case CRSERR_WRONG_DB:
1258 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1259 errmsg(
"cross-database references are not implemented: %s",
1263 case CRSERR_TOO_MANY:
1265 (
errcode(ERRCODE_SYNTAX_ERROR),
1266 errmsg(
"improper qualified name (too many dotted names): %s",
1296 bool found_table =
false;
1326 (
errcode(ERRCODE_SYNTAX_ERROR),
1327 errmsg(
"SELECT * with no tables specified is not valid"),
1373 int sublevels_up,
int location,
bool make_target_entry)
1375 if (make_target_entry)
1399 Assert(perminfo != NULL);
1424 bool make_target_entry)
1464 ((
Var *) expr)->vartype == RECORDOID)
1471 numAttrs = tupleDesc->
natts;
1472 for (
i = 0;
i < numAttrs;
i++)
1477 if (att->attisdropped)
1483 fselect->resulttype = att->atttypid;
1484 fselect->resulttypmod = att->atttypmod;
1486 fselect->resultcollid = att->attcollation;
1488 if (make_target_entry)
1500 result =
lappend(result, fselect);
1529 Assert(var->vartype == RECORDOID);
1569 Assert(lname == NULL && lvar == NULL);
1574 expr = (
Node *) var;
1595 if (ste == NULL || ste->resjunk)
1596 elog(
ERROR,
"subquery %s does not have attribute %d",
1597 rte->eref->aliasname,
attnum);
1613 for (levelsup = 0; levelsup < netlevelsup; levelsup++)
1649 if (!rte->self_reference)
1655 if (ste == NULL || ste->resjunk)
1656 elog(
ERROR,
"CTE %s does not have attribute %d",
1657 rte->eref->aliasname,
attnum);
1758 foreach(l, ((
ColumnRef *) node)->fields)
1772 case T_A_Indirection:
1779 foreach(l,
ind->indirection)
1810 if (((
TypeCast *) node)->typeName != NULL)
1817 case T_CollateClause:
1819 case T_GroupingFunc:
1823 case T_MergeSupportFunc:
1825 *
name =
"merge_action";
1828 switch (((
SubLink *) node)->subLinkType)
1855 *
name = te->resname;
1887 case T_CoalesceExpr:
1903 case T_SQLValueFunction:
1908 *
name =
"current_date";
1912 *
name =
"current_time";
1916 *
name =
"current_timestamp";
1920 *
name =
"localtime";
1924 *
name =
"localtimestamp";
1927 *
name =
"current_role";
1930 *
name =
"current_user";
1936 *
name =
"session_user";
1939 *
name =
"current_catalog";
1942 *
name =
"current_schema";
1948 switch (((
XmlExpr *) node)->op)
1951 *
name =
"xmlconcat";
1954 *
name =
"xmlelement";
1957 *
name =
"xmlforest";
1969 *
name =
"xmlserialize";
1976 case T_XmlSerialize:
1978 *
name =
"xmlserialize";
1980 case T_JsonParseExpr:
1984 case T_JsonScalarExpr:
1986 *
name =
"json_scalar";
1988 case T_JsonSerializeExpr:
1990 *
name =
"json_serialize";
1992 case T_JsonObjectConstructor:
1994 *
name =
"json_object";
1996 case T_JsonArrayConstructor:
1997 case T_JsonArrayQueryConstructor:
1999 *
name =
"json_array";
2001 case T_JsonObjectAgg:
2003 *
name =
"json_objectagg";
2005 case T_JsonArrayAgg:
2007 *
name =
"json_arrayagg";
2009 case T_JsonFuncExpr:
2014 *
name =
"json_exists";
2017 *
name =
"json_query";
2020 *
name =
"json_value";
2024 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 * list_truncate(List *list, int new_size)
List * lappend(List *list, void *datum)
List * lappend_int(List *list, int datum)
List * list_concat(List *list1, const List *list2)
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)
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Const * makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid)
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
Var * makeVar(int varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
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_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId, int32 targetTypeMod, CoercionContext ccontext, CoercionForm cformat, int location)
Node * coerce_to_domain(Node *arg, Oid baseTypeId, int32 baseTypeMod, Oid typeId, CoercionContext ccontext, CoercionForm cformat, int location, bool hideInputCoercion)
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)
SubscriptingRef * transformContainerSubscripts(ParseState *pstate, Node *containerBase, Oid containerType, int32 containerTypMod, List *indirection, bool isAssignment)
int parser_errposition(ParseState *pstate, int location)
void transformContainerType(Oid *containerType, int32 *containerTypmod)
@ EXPR_KIND_UPDATE_TARGET
@ EXPR_KIND_UPDATE_SOURCE
RangeTblEntry * GetRTEByRangeTablePosn(ParseState *pstate, int varno, int sublevels_up)
void markVarForSelectPriv(ParseState *pstate, Var *var)
void errorMissingRTE(ParseState *pstate, RangeVar *relation)
TargetEntry * get_tle_by_resno(List *tlist, AttrNumber resno)
ParseNamespaceItem * GetNSItemByRangeTablePosn(ParseState *pstate, int varno, int sublevels_up)
ParseNamespaceItem * refnameNamespaceItem(ParseState *pstate, const char *schemaname, const char *refname, int location, int *sublevels_up)
Oid attnumTypeId(Relation rd, int attid)
List * expandNSItemVars(ParseState *pstate, ParseNamespaceItem *nsitem, int sublevels_up, int location, List **colnames)
List * expandNSItemAttrs(ParseState *pstate, ParseNamespaceItem *nsitem, int sublevels_up, bool require_col_privs, int location)
void expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up, int location, bool include_dropped, List **colnames, List **colvars)
CommonTableExpr * GetCTEForRTE(ParseState *pstate, RangeTblEntry *rte, int rtelevelsup)
int attnameAttNum(Relation rd, const char *attname, bool sysColOK)
static List * ExpandColumnRefStar(ParseState *pstate, ColumnRef *cref, bool make_target_entry)
List * transformTargetList(ParseState *pstate, List *targetlist, ParseExprKind exprKind)
static int FigureColnameInternal(Node *node, char **name)
Expr * transformAssignedExpr(ParseState *pstate, Expr *expr, ParseExprKind exprKind, const char *colname, int attrno, List *indirection, int location)
static void markTargetListOrigin(ParseState *pstate, TargetEntry *tle, Var *var, int levelsup)
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)
void updateTargetListEntry(ParseState *pstate, TargetEntry *tle, char *colname, int attrno, List *indirection, int location)
void resolveTargetListUnknowns(ParseState *pstate, List *targetlist)
TargetEntry * transformTargetEntry(ParseState *pstate, Node *node, Node *expr, ParseExprKind exprKind, char *colname, bool resjunk)
void markTargetListOrigins(ParseState *pstate, List *targetlist)
List * checkInsertTargets(ParseState *pstate, List *cols, List **attrnos)
static List * ExpandIndirectionStar(ParseState *pstate, A_Indirection *ind, bool make_target_entry, ParseExprKind exprKind)
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)
static List * ExpandAllTables(ParseState *pstate, int location)
List * transformExpressionList(ParseState *pstate, List *exprlist, ParseExprKind exprKind, bool allowDefault)
char * FigureColname(Node *node)
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 ListCell * list_head(const List *l)
static void * list_nth(const List *list, int n)
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
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)
#define TupleDescAttr(tupdesc, i)