* Label every SetOperationStmt in the tree with the given datatypes. */
| 2475 | * Label every SetOperationStmt in the tree with the given datatypes. |
| 2476 | */ |
| 2477 | static void |
| 2478 | coerceSetOpTypes(ParseState *pstate, Node *sop, |
| 2479 | List *preselected_coltypes, List *preselected_coltypmods, |
| 2480 | List **targetlist) |
| 2481 | { |
| 2482 | if (IsA(sop, RangeTblRef)) |
| 2483 | { |
| 2484 | RangeTblEntry *rte = rt_fetch((((RangeTblRef *) sop)->rtindex), pstate->p_rtable); |
| 2485 | Query *selectQuery = rte->subquery; |
| 2486 | ListCell *tl; |
| 2487 | |
| 2488 | /* |
| 2489 | * Extract a list of the non-junk TLEs for upper-level processing. |
| 2490 | * This is the same we did in the first pass, in |
| 2491 | * transformSetOperationTree_internal(). |
| 2492 | */ |
| 2493 | if (targetlist) |
| 2494 | { |
| 2495 | *targetlist = NIL; |
| 2496 | foreach(tl, selectQuery->targetList) |
| 2497 | { |
| 2498 | TargetEntry *tle = (TargetEntry *) lfirst(tl); |
| 2499 | |
| 2500 | if (!tle->resjunk) |
| 2501 | *targetlist = lappend(*targetlist, tle); |
| 2502 | } |
| 2503 | } |
| 2504 | return; |
| 2505 | } |
| 2506 | else |
| 2507 | { |
| 2508 | SetOperationStmt *op = (SetOperationStmt *) sop; |
| 2509 | List *ltargetlist; |
| 2510 | List *rtargetlist; |
| 2511 | ListCell *ltl; |
| 2512 | ListCell *rtl; |
| 2513 | ListCell *pct; |
| 2514 | ListCell *pcm; |
| 2515 | const char *context; |
| 2516 | bool recursive = (pstate->p_parent_cte && |
| 2517 | pstate->p_parent_cte->cterecursive); |
| 2518 | |
| 2519 | Assert(IsA(op, SetOperationStmt)); |
| 2520 | |
| 2521 | context = (op->op == SETOP_UNION ? "UNION" : |
| 2522 | op->op == SETOP_INTERSECT ? "INTERSECT" : |
| 2523 | "EXCEPT"); |
| 2524 | |
| 2525 | /* Recurse to determine the children's types first */ |
| 2526 | coerceSetOpTypes(pstate, op->larg, |
| 2527 | preselected_coltypes, preselected_coltypmods, |
| 2528 | <argetlist); |
| 2529 | |
| 2530 | coerceSetOpTypes(pstate, op->rarg, |
| 2531 | preselected_coltypes, preselected_coltypmods, |
| 2532 | &rtargetlist); |
| 2533 | |
| 2534 | /* |
no test coverage detected