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)
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");
303 errmsg(
"could not identify an equality operator for type %s",
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");
336 errmsg(
"WITH clause containing a data-modifying statement must be at the top level"),
344 query->canSetTag =
false;
346 if (!cte->cterecursive)
379 elog(
ERROR,
"wrong number of output columns in WITH");
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."),
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."),
407 elog(
ERROR,
"wrong number of output columns in WITH");
418 if (!cte->cterecursive)
421 errmsg(
"WITH query is not recursive"),
452 errmsg(
"with a SEARCH or CYCLE clause, the left side of the UNION must be a SELECT")));
457 errmsg(
"with a SEARCH or CYCLE clause, the right side of the UNION must be a SELECT")));
472 errmsg(
"search column \"%s\" not in WITH query column list",
479 errmsg(
"search column \"%s\" specified more than once",
488 errmsg(
"search sequence column name \"%s\" already used in WITH query column list",
505 errmsg(
"cycle column \"%s\" not in WITH query column list",
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"),
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;
623 if (cte->cterecursive && coltype ==
UNKNOWNOID)
630 cte->ctecoltypes =
lappend_oid(cte->ctecoltypes, coltype);
637 errmsg(
"WITH query \"%s\" has %d columns available but %d columns specified",
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++)
882 errmsg(
"mutual recursion between WITH items is not implemented"),
902 for (
j =
i + 1;
j < numitems;
j++)
927 if (!cte->cterecursive)
934 errmsg(
"recursive query \"%s\" must not contain data-modifying statements",
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)
977 errmsg(
"ORDER BY in a recursive query is not implemented"),
980 if (
stmt->limitOffset)
983 errmsg(
"OFFSET in a recursive query is not implemented"),
986 if (
stmt->limitCount)
989 errmsg(
"LIMIT in a recursive query is not implemented"),
992 if (
stmt->lockingClause)
995 errmsg(
"FOR UPDATE/SHARE in a recursive query is not implemented"),
1019 elog(
ERROR,
"missing recursive reference");
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)
1178 elog(
ERROR,
"unrecognized join type: %d",
Bitmapset * bms_del_member(Bitmapset *a, int x)
Bitmapset * bms_add_member(Bitmapset *a, int x)
#define Assert(condition)
#define OidIsValid(objectId)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
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)
ParseState * parentParseState
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)
String * makeString(char *str)