* expandRTE -- expand the columns of a rangetable entry * * This creates lists of an RTE's column names (aliases if provided, else * real names) and Vars for each column. Only user columns are considered. * If include_dropped is false then dropped columns are omitted from the * results. If include_dropped is true then empty strings and NULL constants * (not Vars!) are returned for dropped
| 2908 | * output pointer for the unwanted one. |
| 2909 | */ |
| 2910 | void |
| 2911 | expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up, |
| 2912 | int location, bool include_dropped, |
| 2913 | List **colnames, List **colvars) |
| 2914 | { |
| 2915 | int varattno; |
| 2916 | |
| 2917 | if (colnames) |
| 2918 | *colnames = NIL; |
| 2919 | if (colvars) |
| 2920 | *colvars = NIL; |
| 2921 | |
| 2922 | switch (rte->rtekind) |
| 2923 | { |
| 2924 | case RTE_RELATION: |
| 2925 | /* Ordinary relation RTE */ |
| 2926 | expandRelation(rte->relid, rte->eref, |
| 2927 | rtindex, sublevels_up, location, |
| 2928 | include_dropped, colnames, colvars); |
| 2929 | break; |
| 2930 | case RTE_SUBQUERY: |
| 2931 | { |
| 2932 | /* Subquery RTE */ |
| 2933 | ListCell *aliasp_item = list_head(rte->eref->colnames); |
| 2934 | ListCell *tlistitem; |
| 2935 | |
| 2936 | varattno = 0; |
| 2937 | foreach(tlistitem, rte->subquery->targetList) |
| 2938 | { |
| 2939 | TargetEntry *te = (TargetEntry *) lfirst(tlistitem); |
| 2940 | |
| 2941 | if (te->resjunk) |
| 2942 | continue; |
| 2943 | varattno++; |
| 2944 | Assert(varattno == te->resno); |
| 2945 | |
| 2946 | /* |
| 2947 | * In scenarios where columns have been added to a view |
| 2948 | * since the outer query was originally parsed, there can |
| 2949 | * be more items in the subquery tlist than the outer |
| 2950 | * query expects. We should ignore such extra column(s) |
| 2951 | * --- compare the behavior for composite-returning |
| 2952 | * functions, in the RTE_FUNCTION case below. |
| 2953 | */ |
| 2954 | if (!aliasp_item) |
| 2955 | break; |
| 2956 | |
| 2957 | if (colnames) |
| 2958 | { |
| 2959 | char *label = strVal(lfirst(aliasp_item)); |
| 2960 | |
| 2961 | *colnames = lappend(*colnames, makeString(pstrdup(label))); |
| 2962 | } |
| 2963 | |
| 2964 | if (colvars) |
| 2965 | { |
| 2966 | Var *varnode; |
| 2967 |
no test coverage detected