204{
225
226 Assert(cte->search_clause || cte->cycle_clause);
227
229
231
232
233
234
235
239
242
245
248
249
250
251
252 if (cte->search_clause)
253 {
254 if (cte->search_clause->search_breadth_first)
256 else
258 }
259
260
261
262
263 if (cte->search_clause)
265 if (cte->cycle_clause)
266 {
269 if (cte->search_clause)
270 {
273 }
274 }
275
276
277
278
281 newq1->canSetTag =
true;
282
292
296
297
298
299
301 {
303
308 0);
313 }
314
315 if (cte->search_clause)
316 {
318
320 if (cte->search_clause->search_breadth_first)
321 {
327 }
328 else
332 cte->search_clause->search_seq_column,
333 false);
335 }
336 if (cte->cycle_clause)
337 {
340 cte->cycle_clause->cycle_mark_column,
341 false);
346 cte->cycle_clause->cycle_path_column,
347 false);
349 }
350
352
353 if (cte->search_clause)
354 {
356 }
357 if (cte->cycle_clause)
358 {
361 }
362
363
364
365
368 newq2->canSetTag =
true;
369
373 if (cte->search_clause)
374 {
376 }
377 if (cte->cycle_clause)
378 {
381 }
384
385
386
387
388
389
390
391
392
393
394
396 {
398
402 {
404 break;
405 }
406 }
410 errmsg(
"with a SEARCH or CYCLE clause, the recursive reference to WITH query \"%s\" must be at the top level of its right-hand SELECT",
412
415
416
417
418
419 if (cte->search_clause)
420 {
422
423
428 cte->search_clause->search_seq_column,
429 false);
431 }
432 if (cte->cycle_clause)
433 {
435
436
438 cte->cycle_clause->cycle_mark_type,
439 cte->cycle_clause->cycle_mark_typmod,
440 cte->cycle_clause->cycle_mark_collation, 0);
443 cte->cycle_clause->cycle_mark_column,
444 false);
446
447
452 cte->cycle_clause->cycle_path_column,
453 false);
455 }
456
460
463
464 if (cte->cycle_clause)
465 {
467
468
469
470
473 cte->cycle_clause->cycle_mark_type,
474 cte->cycle_clause->cycle_mark_typmod,
475 cte->cycle_clause->cycle_mark_collation, 0),
476 (
Expr *) cte->cycle_clause->cycle_mark_value,
478 cte->cycle_clause->cycle_mark_collation);
479
481 }
482 else
484
485
486
487
489 {
491
496 0);
501 }
502
503 if (cte->search_clause)
504 {
506
507 if (cte->search_clause->search_breadth_first)
508 {
511
512
513
514
515
517
522 fs->resulttypmod = -1;
523
525
527
529 }
530 else
531 {
532
533
534
536 }
539 cte->search_clause->search_seq_column,
540 false);
542 }
543
544 if (cte->cycle_clause)
545 {
549
550
551
552
553
560
563 caseexpr->casetype = cte->cycle_clause->cycle_mark_type;
564 caseexpr->casecollid = cte->cycle_clause->cycle_mark_collation;
568 casewhen->result = (
Expr *) cte->cycle_clause->cycle_mark_value;
570 caseexpr->defresult = (
Expr *) cte->cycle_clause->cycle_mark_default;
571
574 cte->cycle_clause->cycle_mark_column,
575 false);
577
578
579
580
583 cte->cycle_clause->cycle_path_column,
584 false);
586 }
587
589
590 if (cte->search_clause)
591 {
593 }
594 if (cte->cycle_clause)
595 {
598 }
599
600
601
602
603 if (cte->search_clause)
604 {
611 }
612 if (cte->cycle_clause)
613 {
615 sos->colTypmods =
lappend_int(
sos->colTypmods, cte->cycle_clause->cycle_mark_typmod);
616 sos->colCollations =
lappend_oid(
sos->colCollations, cte->cycle_clause->cycle_mark_collation);
620
627 }
628
629
630
631
632 if (cte->search_clause)
633 {
638 cte->search_clause->search_seq_column,
639 false));
640 }
641 if (cte->cycle_clause)
642 {
645 cte->cycle_clause->cycle_mark_type,
646 cte->cycle_clause->cycle_mark_typmod,
647 cte->cycle_clause->cycle_mark_collation, 0),
649 cte->cycle_clause->cycle_mark_column,
650 false));
655 cte->cycle_clause->cycle_path_column,
656 false));
657 }
658
659
660
661
662 cte->ctecolnames =
ewcl;
663 if (cte->search_clause)
664 {
666 cte->ctecoltypmods =
lappend_int(cte->ctecoltypmods, -1);
668 }
669 if (cte->cycle_clause)
670 {
671 cte->ctecoltypes =
lappend_oid(cte->ctecoltypes, cte->cycle_clause->cycle_mark_type);
672 cte->ctecoltypmods =
lappend_int(cte->ctecoltypmods, cte->cycle_clause->cycle_mark_typmod);
673 cte->ctecolcollations =
lappend_oid(cte->ctecolcollations, cte->cycle_clause->cycle_mark_collation);
674
676 cte->ctecoltypmods =
lappend_int(cte->ctecoltypmods, -1);
678 }
679
680 return cte;
681}
#define InvalidAttrNumber
#define Assert(condition)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
List * lappend(List *list, void *datum)
List * lappend_int(List *list, int datum)
List * lappend_oid(List *list, Oid datum)
List * lcons(void *datum, List *list)
Alias * makeAlias(const char *aliasname, List *colnames)
FromExpr * makeFromExpr(List *fromlist, Node *quals)
Var * makeVar(int varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
FuncExpr * makeFuncExpr(Oid funcid, Oid rettype, List *args, Oid funccollid, Oid inputcollid, CoercionForm fformat)
Expr * make_opclause(Oid opno, Oid opresulttype, bool opretset, Expr *leftop, Expr *rightop, Oid opcollid, Oid inputcollid)
Const * makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
#define castNode(_type_, nodeptr)
SortGroupClause * makeSortGroupClauseForSetOp(Oid rescoltype, bool require_hash)
#define rt_fetch(rangetable_index, rangetable)
static int list_length(const List *l)
static Oid list_nth_oid(const List *list, int n)
static void * list_nth(const List *list, int n)
#define list_nth_node(type, list, n)
#define list_make2(x1, x2)
static int list_nth_int(const List *list, int n)
static Datum Int64GetDatum(int64 X)
void IncrementVarSublevelsUp(Node *node, int delta_sublevels_up, int min_sublevels_up)
static RowExpr * make_path_rowexpr(const CommonTableExpr *cte, const List *col_list)
static Expr * make_path_initial_array(RowExpr *rowexpr)
static Expr * make_path_cat_expr(RowExpr *rowexpr, AttrNumber path_varattno)
String * makeString(char *str)