46 gettext_noop(
"recursive reference to query \"%s\" must not appear within its non-recursive term"),
48 gettext_noop(
"recursive reference to query \"%s\" must not appear within a subquery"),
50 gettext_noop(
"recursive reference to query \"%s\" must not appear within an outer join"),
52 gettext_noop(
"recursive reference to query \"%s\" must not appear within INTERSECT"),
54 gettext_noop(
"recursive reference to query \"%s\" must not appear within EXCEPT")
125 foreach(lc, withClause->
ctes)
136 (
errcode(ERRCODE_DUPLICATE_ALIAS),
137 errmsg(
"WITH query name \"%s\" specified more than once",
142 cte->cterecursive =
false;
143 cte->cterefcount = 0;
171 foreach(lc, withClause->
ctes)
223 foreach(lc, withClause->
ctes)
283 "CYCLE/SET/DEFAULT");
302 errcode(ERRCODE_UNDEFINED_FUNCTION),
303 errmsg(
"could not identify an equality operator for type %s",
308 errcode(ERRCODE_UNDEFINED_FUNCTION),
309 errmsg(
"could not identify an inequality operator for type %s",
324 elog(
ERROR,
"unexpected non-Query statement in WITH");
326 elog(
ERROR,
"unexpected utility statement in WITH");
335 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
336 errmsg(
"WITH clause containing a data-modifying statement must be at the top level"),
344 query->canSetTag =
false;
346 if (!cte->cterecursive)
366 lctypmod =
list_head(cte->ctecoltypmods);
367 lccoll =
list_head(cte->ctecolcollations);
378 if (lctyp == NULL || lctypmod == NULL || lccoll == NULL)
379 elog(
ERROR,
"wrong number of output columns in WITH");
384 (
errcode(ERRCODE_DATATYPE_MISMATCH),
385 errmsg(
"recursive query \"%s\" column %d has type %s in non-recursive term but type %s overall",
391 errhint(
"Cast the output of the non-recursive term to the correct type."),
395 (
errcode(ERRCODE_COLLATION_MISMATCH),
396 errmsg(
"recursive query \"%s\" column %d has collation \"%s\" in non-recursive term but collation \"%s\" overall",
400 errhint(
"Use the COLLATE clause to set the collation of the non-recursive term."),
402 lctyp =
lnext(cte->ctecoltypes, lctyp);
403 lctypmod =
lnext(cte->ctecoltypmods, lctypmod);
404 lccoll =
lnext(cte->ctecolcollations, lccoll);
406 if (lctyp != NULL || lctypmod != NULL || lccoll != NULL)
407 elog(
ERROR,
"wrong number of output columns in WITH");
413 if (search_clause || cycle_clause)
418 if (!cte->cterecursive)
420 (
errcode(ERRCODE_SYNTAX_ERROR),
421 errmsg(
"WITH query is not recursive"),
451 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
452 errmsg(
"with a SEARCH or CYCLE clause, the left side of the UNION must be a SELECT")));
456 (
errcode(ERRCODE_SYNTAX_ERROR),
457 errmsg(
"with a SEARCH or CYCLE clause, the right side of the UNION must be a SELECT")));
471 (
errcode(ERRCODE_SYNTAX_ERROR),
472 errmsg(
"search column \"%s\" not in WITH query column list",
478 (
errcode(ERRCODE_DUPLICATE_COLUMN),
479 errmsg(
"search column \"%s\" specified more than once",
488 errmsg(
"search sequence column name \"%s\" already used in WITH query column list",
504 (
errcode(ERRCODE_SYNTAX_ERROR),
505 errmsg(
"cycle column \"%s\" not in WITH query column list",
511 (
errcode(ERRCODE_DUPLICATE_COLUMN),
512 errmsg(
"cycle column \"%s\" specified more than once",
521 errmsg(
"cycle mark column name \"%s\" already used in WITH query column list",
528 errmsg(
"cycle path column name \"%s\" already used in WITH query column list",
536 errmsg(
"cycle mark column name and cycle path column name are the same"),
540 if (search_clause && cycle_clause)
546 errmsg(
"search sequence column name and cycle mark column name are the same"),
553 errmsg(
"search sequence column name and cycle path column name are the same"),
587 cte->ctecolnames =
copyObject(cte->aliascolnames);
588 cte->ctecoltypes = cte->ctecoltypmods = cte->ctecolcollations =
NIL;
591 foreach(tlistitem, tlist)
602 if (varattno > numaliases)
606 attrname =
pstrdup(te->resname);
623 if (cte->cterecursive && coltype == UNKNOWNOID)
628 colcoll = DEFAULT_COLLATION_OID;
630 cte->ctecoltypes =
lappend_oid(cte->ctecoltypes, coltype);
631 cte->ctecoltypmods =
lappend_int(cte->ctecoltypmods, coltypmod);
632 cte->ctecolcollations =
lappend_oid(cte->ctecolcollations, colcoll);
634 if (varattno < numaliases)
636 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
637 errmsg(
"WITH query \"%s\" has %d columns available but %d columns specified",
638 cte->
ctename, varattno, numaliases),
690 foreach(lc2, withlist)
718 cte->cterecursive =
true;
730 if (
stmt->withClause)
743 if (
stmt->withClause)
756 if (
stmt->withClause)
769 if (
stmt->withClause)
782 if (
stmt->withClause)
824 foreach(lc, withClause->
ctes)
842 foreach(lc, withClause->
ctes)
869 for (
i = 0;
i < numitems;
i++)
872 for (
j =
i;
j < numitems;
j++)
881 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
882 errmsg(
"mutual recursion between WITH items is not implemented"),
902 for (
j =
i + 1;
j < numitems;
j++)
927 if (!cte->cterecursive)
933 (
errcode(ERRCODE_INVALID_RECURSION),
934 errmsg(
"recursive query \"%s\" must not contain data-modifying statements",
941 (
errcode(ERRCODE_INVALID_RECURSION),
942 errmsg(
"recursive query \"%s\" does not have the form non-recursive-term UNION [ALL] recursive-term",
954 if (
stmt->withClause)
974 if (
stmt->sortClause)
976 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
977 errmsg(
"ORDER BY in a recursive query is not implemented"),
980 if (
stmt->limitOffset)
982 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
983 errmsg(
"OFFSET in a recursive query is not implemented"),
986 if (
stmt->limitCount)
988 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
989 errmsg(
"LIMIT in a recursive query is not implemented"),
992 if (
stmt->lockingClause)
994 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
995 errmsg(
"FOR UPDATE/SHARE in a recursive query is not implemented"),
1019 elog(
ERROR,
"missing recursive reference");
1049 foreach(lc2, withlist)
1065 (
errcode(ERRCODE_INVALID_RECURSION),
1073 (
errcode(ERRCODE_INVALID_RECURSION),
1074 errmsg(
"recursive reference to query \"%s\" must not appear more than once",
1087 if (
stmt->withClause)
1089 if (
stmt->withClause->recursive)
1098 foreach(lc,
stmt->withClause->ctes)
1114 foreach(lc,
stmt->withClause->ctes)
1146 switch (
j->jointype)
1158 cstate->
context = save_context;
1166 cstate->
context = save_context;
1173 cstate->
context = save_context;
1178 elog(
ERROR,
"unrecognized join type: %d",
1193 cstate->
context = save_context;
1235 cstate->
context = save_context;
1254 cstate->
context = save_context;
Bitmapset * bms_del_member(Bitmapset *a, int x)
Bitmapset * bms_add_member(Bitmapset *a, int x)
#define OidIsValid(objectId)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
Assert(PointerIsAligned(start, uint64))
if(TABLE==NULL||TABLE_index==NULL)
List * lappend(List *list, void *datum)
List * list_delete_first(List *list)
List * list_copy(const List *oldlist)
List * lappend_int(List *list, int datum)
List * lappend_oid(List *list, Oid datum)
List * lcons(void *datum, List *list)
bool list_member(const List *list, const void *datum)
char * get_collation_name(Oid colloid)
Oid get_negator(Oid opno)
char * pstrdup(const char *in)
void * palloc0(Size size)
Oid exprType(const Node *expr)
int32 exprTypmod(const Node *expr)
Oid exprCollation(const Node *expr)
int exprLocation(const Node *expr)
#define raw_expression_tree_walker(n, w, c)
#define IsA(nodeptr, _type_)
#define castNode(_type_, nodeptr)
Node * coerce_to_common_type(ParseState *pstate, Node *node, Oid targetTypeId, const char *context)
int32 select_common_typmod(ParseState *pstate, List *exprs, Oid common_type)
Oid select_common_type(ParseState *pstate, List *exprs, const char *context, Node **which_expr)
Oid select_common_collation(ParseState *pstate, List *exprs, bool none_ok)
static void WalkInnerWith(Node *stmt, WithClause *withClause, CteState *cstate)
static void checkWellFormedSelectStmt(SelectStmt *stmt, CteState *cstate)
@ RECURSION_NONRECURSIVETERM
static void makeDependencyGraph(CteState *cstate)
void analyzeCTETargetList(ParseState *pstate, CommonTableExpr *cte, List *tlist)
static void checkWellFormedRecursion(CteState *cstate)
List * transformWithClause(ParseState *pstate, WithClause *withClause)
static void TopologicalSort(ParseState *pstate, CteItem *items, int numitems)
static bool makeDependencyGraphWalker(Node *node, CteState *cstate)
static bool checkWellFormedRecursionWalker(Node *node, CteState *cstate)
static const char *const recursion_errormsgs[]
static void analyzeCTE(ParseState *pstate, CommonTableExpr *cte)
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
int parser_errposition(ParseState *pstate, int location)
#define GetCTETargetList(cte)
Query * parse_sub_analyze(Node *parseTree, ParseState *parentParseState, CommonTableExpr *parentCTE, bool locked_from_parent, bool resolve_unknowns)
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define for_each_cell(cell, lst, initcell)
static ListCell * list_head(const List *l)
static ListCell * lnext(const List *l, const ListCell *c)
#define list_make2(x1, x2)
Node * cycle_mark_default
ParseState * parentParseState
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)
String * makeString(char *str)