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")
124 foreach(lc, withClause->
ctes)
135 (
errcode(ERRCODE_DUPLICATE_ALIAS),
136 errmsg(
"WITH query name \"%s\" specified more than once",
141 cte->cterecursive =
false;
142 cte->cterefcount = 0;
170 foreach(lc, withClause->
ctes)
222 foreach(lc, withClause->
ctes)
282 "CYCLE/SET/DEFAULT");
301 errcode(ERRCODE_UNDEFINED_FUNCTION),
302 errmsg(
"could not identify an equality operator for type %s",
307 errcode(ERRCODE_UNDEFINED_FUNCTION),
308 errmsg(
"could not identify an inequality operator for type %s",
323 elog(
ERROR,
"unexpected non-Query statement in WITH");
325 elog(
ERROR,
"unexpected utility statement in WITH");
334 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
335 errmsg(
"WITH clause containing a data-modifying statement must be at the top level"),
343 query->canSetTag =
false;
345 if (!cte->cterecursive)
365 lctypmod =
list_head(cte->ctecoltypmods);
366 lccoll =
list_head(cte->ctecolcollations);
377 if (lctyp == NULL || lctypmod == NULL || lccoll == NULL)
378 elog(
ERROR,
"wrong number of output columns in WITH");
383 (
errcode(ERRCODE_DATATYPE_MISMATCH),
384 errmsg(
"recursive query \"%s\" column %d has type %s in non-recursive term but type %s overall",
390 errhint(
"Cast the output of the non-recursive term to the correct type."),
394 (
errcode(ERRCODE_COLLATION_MISMATCH),
395 errmsg(
"recursive query \"%s\" column %d has collation \"%s\" in non-recursive term but collation \"%s\" overall",
399 errhint(
"Use the COLLATE clause to set the collation of the non-recursive term."),
401 lctyp =
lnext(cte->ctecoltypes, lctyp);
402 lctypmod =
lnext(cte->ctecoltypmods, lctypmod);
403 lccoll =
lnext(cte->ctecolcollations, lccoll);
405 if (lctyp != NULL || lctypmod != NULL || lccoll != NULL)
406 elog(
ERROR,
"wrong number of output columns in WITH");
412 if (search_clause || cycle_clause)
417 if (!cte->cterecursive)
419 (
errcode(ERRCODE_SYNTAX_ERROR),
420 errmsg(
"WITH query is not recursive"),
450 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
451 errmsg(
"with a SEARCH or CYCLE clause, the left side of the UNION must be a SELECT")));
455 (
errcode(ERRCODE_SYNTAX_ERROR),
456 errmsg(
"with a SEARCH or CYCLE clause, the right side of the UNION must be a SELECT")));
470 (
errcode(ERRCODE_SYNTAX_ERROR),
471 errmsg(
"search column \"%s\" not in WITH query column list",
477 (
errcode(ERRCODE_DUPLICATE_COLUMN),
478 errmsg(
"search column \"%s\" specified more than once",
487 errmsg(
"search sequence column name \"%s\" already used in WITH query column list",
503 (
errcode(ERRCODE_SYNTAX_ERROR),
504 errmsg(
"cycle column \"%s\" not in WITH query column list",
510 (
errcode(ERRCODE_DUPLICATE_COLUMN),
511 errmsg(
"cycle column \"%s\" specified more than once",
520 errmsg(
"cycle mark column name \"%s\" already used in WITH query column list",
527 errmsg(
"cycle path column name \"%s\" already used in WITH query column list",
535 errmsg(
"cycle mark column name and cycle path column name are the same"),
539 if (search_clause && cycle_clause)
545 errmsg(
"search sequence column name and cycle mark column name are the same"),
552 errmsg(
"search sequence column name and cycle path column name are the same"),
586 cte->ctecolnames =
copyObject(cte->aliascolnames);
587 cte->ctecoltypes = cte->ctecoltypmods = cte->ctecolcollations =
NIL;
590 foreach(tlistitem, tlist)
601 if (varattno > numaliases)
605 attrname =
pstrdup(te->resname);
622 if (cte->cterecursive && coltype == UNKNOWNOID)
627 colcoll = DEFAULT_COLLATION_OID;
629 cte->ctecoltypes =
lappend_oid(cte->ctecoltypes, coltype);
630 cte->ctecoltypmods =
lappend_int(cte->ctecoltypmods, coltypmod);
631 cte->ctecolcollations =
lappend_oid(cte->ctecolcollations, colcoll);
633 if (varattno < numaliases)
635 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
636 errmsg(
"WITH query \"%s\" has %d columns available but %d columns specified",
637 cte->
ctename, varattno, numaliases),
689 foreach(lc2, withlist)
717 cte->cterecursive =
true;
730 if (
stmt->withClause)
732 if (
stmt->withClause->recursive)
741 foreach(lc,
stmt->withClause->ctes)
759 foreach(lc,
stmt->withClause->ctes)
803 for (
i = 0;
i < numitems;
i++)
806 for (
j =
i;
j < numitems;
j++)
815 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
816 errmsg(
"mutual recursion between WITH items is not implemented"),
836 for (
j =
i + 1;
j < numitems;
j++)
861 if (!cte->cterecursive)
867 (
errcode(ERRCODE_INVALID_RECURSION),
868 errmsg(
"recursive query \"%s\" must not contain data-modifying statements",
875 (
errcode(ERRCODE_INVALID_RECURSION),
876 errmsg(
"recursive query \"%s\" does not have the form non-recursive-term UNION [ALL] recursive-term",
888 if (
stmt->withClause)
908 if (
stmt->sortClause)
910 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
911 errmsg(
"ORDER BY in a recursive query is not implemented"),
914 if (
stmt->limitOffset)
916 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
917 errmsg(
"OFFSET in a recursive query is not implemented"),
920 if (
stmt->limitCount)
922 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
923 errmsg(
"LIMIT in a recursive query is not implemented"),
926 if (
stmt->lockingClause)
928 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
929 errmsg(
"FOR UPDATE/SHARE in a recursive query is not implemented"),
953 elog(
ERROR,
"missing recursive reference");
983 foreach(lc2, withlist)
999 (
errcode(ERRCODE_INVALID_RECURSION),
1007 (
errcode(ERRCODE_INVALID_RECURSION),
1008 errmsg(
"recursive reference to query \"%s\" must not appear more than once",
1021 if (
stmt->withClause)
1023 if (
stmt->withClause->recursive)
1032 foreach(lc,
stmt->withClause->ctes)
1048 foreach(lc,
stmt->withClause->ctes)
1080 switch (
j->jointype)
1092 cstate->
context = save_context;
1100 cstate->
context = save_context;
1107 cstate->
context = save_context;
1112 elog(
ERROR,
"unrecognized join type: %d",
1127 cstate->
context = save_context;
1169 cstate->
context = save_context;
1188 cstate->
context = save_context;
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,...)
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 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)