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)
132 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
133 errmsg(
"MERGE not supported in WITH query"),
142 (
errcode(ERRCODE_DUPLICATE_ALIAS),
143 errmsg(
"WITH query name \"%s\" specified more than once",
148 cte->cterecursive =
false;
149 cte->cterefcount = 0;
176 foreach(lc, withClause->
ctes)
228 foreach(lc, withClause->
ctes)
288 "CYCLE/SET/DEFAULT");
307 errcode(ERRCODE_UNDEFINED_FUNCTION),
308 errmsg(
"could not identify an equality operator for type %s",
313 errcode(ERRCODE_UNDEFINED_FUNCTION),
314 errmsg(
"could not identify an inequality operator for type %s",
329 elog(
ERROR,
"unexpected non-Query statement in WITH");
331 elog(
ERROR,
"unexpected utility statement in WITH");
340 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
341 errmsg(
"WITH clause containing a data-modifying statement must be at the top level"),
349 query->canSetTag =
false;
351 if (!cte->cterecursive)
371 lctypmod =
list_head(cte->ctecoltypmods);
372 lccoll =
list_head(cte->ctecolcollations);
383 if (lctyp == NULL || lctypmod == NULL || lccoll == NULL)
384 elog(
ERROR,
"wrong number of output columns in WITH");
389 (
errcode(ERRCODE_DATATYPE_MISMATCH),
390 errmsg(
"recursive query \"%s\" column %d has type %s in non-recursive term but type %s overall",
396 errhint(
"Cast the output of the non-recursive term to the correct type."),
400 (
errcode(ERRCODE_COLLATION_MISMATCH),
401 errmsg(
"recursive query \"%s\" column %d has collation \"%s\" in non-recursive term but collation \"%s\" overall",
405 errhint(
"Use the COLLATE clause to set the collation of the non-recursive term."),
407 lctyp =
lnext(cte->ctecoltypes, lctyp);
408 lctypmod =
lnext(cte->ctecoltypmods, lctypmod);
409 lccoll =
lnext(cte->ctecolcollations, lccoll);
411 if (lctyp != NULL || lctypmod != NULL || lccoll != NULL)
412 elog(
ERROR,
"wrong number of output columns in WITH");
418 if (search_clause || cycle_clause)
423 if (!cte->cterecursive)
425 (
errcode(ERRCODE_SYNTAX_ERROR),
426 errmsg(
"WITH query is not recursive"),
456 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
457 errmsg(
"with a SEARCH or CYCLE clause, the left side of the UNION must be a SELECT")));
461 (
errcode(ERRCODE_SYNTAX_ERROR),
462 errmsg(
"with a SEARCH or CYCLE clause, the right side of the UNION must be a SELECT")));
476 (
errcode(ERRCODE_SYNTAX_ERROR),
477 errmsg(
"search column \"%s\" not in WITH query column list",
483 (
errcode(ERRCODE_DUPLICATE_COLUMN),
484 errmsg(
"search column \"%s\" specified more than once",
493 errmsg(
"search sequence column name \"%s\" already used in WITH query column list",
509 (
errcode(ERRCODE_SYNTAX_ERROR),
510 errmsg(
"cycle column \"%s\" not in WITH query column list",
516 (
errcode(ERRCODE_DUPLICATE_COLUMN),
517 errmsg(
"cycle column \"%s\" specified more than once",
526 errmsg(
"cycle mark column name \"%s\" already used in WITH query column list",
533 errmsg(
"cycle path column name \"%s\" already used in WITH query column list",
541 errmsg(
"cycle mark column name and cycle path column name are the same"),
545 if (search_clause && cycle_clause)
551 errmsg(
"search sequence column name and cycle mark column name are the same"),
558 errmsg(
"search sequence column name and cycle path column name are the same"),
592 cte->ctecolnames =
copyObject(cte->aliascolnames);
593 cte->ctecoltypes = cte->ctecoltypmods = cte->ctecolcollations =
NIL;
596 foreach(tlistitem, tlist)
607 if (varattno > numaliases)
611 attrname =
pstrdup(te->resname);
628 if (cte->cterecursive && coltype == UNKNOWNOID)
633 colcoll = DEFAULT_COLLATION_OID;
635 cte->ctecoltypes =
lappend_oid(cte->ctecoltypes, coltype);
636 cte->ctecoltypmods =
lappend_int(cte->ctecoltypmods, coltypmod);
637 cte->ctecolcollations =
lappend_oid(cte->ctecolcollations, colcoll);
639 if (varattno < numaliases)
641 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
642 errmsg(
"WITH query \"%s\" has %d columns available but %d columns specified",
643 cte->
ctename, varattno, numaliases),
695 foreach(lc2, withlist)
723 cte->cterecursive =
true;
736 if (
stmt->withClause)
738 if (
stmt->withClause->recursive)
747 foreach(lc,
stmt->withClause->ctes)
765 foreach(lc,
stmt->withClause->ctes)
809 for (
i = 0;
i < numitems;
i++)
812 for (
j =
i;
j < numitems;
j++)
821 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
822 errmsg(
"mutual recursion between WITH items is not implemented"),
842 for (
j =
i + 1;
j < numitems;
j++)
867 if (!cte->cterecursive)
873 (
errcode(ERRCODE_INVALID_RECURSION),
874 errmsg(
"recursive query \"%s\" must not contain data-modifying statements",
881 (
errcode(ERRCODE_INVALID_RECURSION),
882 errmsg(
"recursive query \"%s\" does not have the form non-recursive-term UNION [ALL] recursive-term",
902 elog(
ERROR,
"missing recursive reference");
905 if (
stmt->withClause)
923 if (
stmt->sortClause)
925 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
926 errmsg(
"ORDER BY in a recursive query is not implemented"),
929 if (
stmt->limitOffset)
931 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
932 errmsg(
"OFFSET in a recursive query is not implemented"),
935 if (
stmt->limitCount)
937 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
938 errmsg(
"LIMIT in a recursive query is not implemented"),
941 if (
stmt->lockingClause)
943 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
944 errmsg(
"FOR UPDATE/SHARE in a recursive query is not implemented"),
976 foreach(lc2, withlist)
992 (
errcode(ERRCODE_INVALID_RECURSION),
1000 (
errcode(ERRCODE_INVALID_RECURSION),
1001 errmsg(
"recursive reference to query \"%s\" must not appear more than once",
1014 if (
stmt->withClause)
1016 if (
stmt->withClause->recursive)
1025 foreach(lc,
stmt->withClause->ctes)
1041 foreach(lc,
stmt->withClause->ctes)
1073 switch (
j->jointype)
1085 cstate->
context = save_context;
1093 cstate->
context = save_context;
1100 cstate->
context = save_context;
1105 elog(
ERROR,
"unrecognized join type: %d",
1120 cstate->
context = save_context;
1162 cstate->context = save_context;
1181 cstate->context = save_context;
Bitmapset * bms_add_member(Bitmapset *a, int x)
Bitmapset * bms_del_member(Bitmapset *a, int x)
#define OidIsValid(objectId)
elog(ERROR, "%s: %s", p2, msg)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
if(TABLE==NULL||TABLE_index==NULL)
Assert(fmt[strlen(fmt) - 1] !='\n')
List * lappend(List *list, void *datum)
List * lappend_int(List *list, int datum)
List * lappend_oid(List *list, Oid datum)
List * list_copy(const List *oldlist)
List * list_delete_first(List *list)
bool list_member(const List *list, const void *datum)
List * lcons(void *datum, List *list)
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)
static void TopologicalSort(ParseState *pstate, CteItem *items, int numitems)
List * transformWithClause(ParseState *pstate, WithClause *withClause)
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)