* transformTargetList() * Turns a list of ResTarget's into a list of TargetEntry's. * * This code acts mostly the same for SELECT, UPDATE, or RETURNING lists; * the main thing is to transform the given expressions (the "val" fields). * The exprKind parameter distinguishes these cases when necessary. */
| 120 | * The exprKind parameter distinguishes these cases when necessary. |
| 121 | */ |
| 122 | List * |
| 123 | transformTargetList(ParseState *pstate, List *targetlist, |
| 124 | ParseExprKind exprKind) |
| 125 | { |
| 126 | List *p_target = NIL; |
| 127 | bool expand_star; |
| 128 | ListCell *o_target; |
| 129 | |
| 130 | /* Shouldn't have any leftover multiassign items at start */ |
| 131 | Assert(pstate->p_multiassign_exprs == NIL); |
| 132 | |
| 133 | /* Expand "something.*" in SELECT and RETURNING, but not UPDATE */ |
| 134 | expand_star = (exprKind != EXPR_KIND_UPDATE_SOURCE); |
| 135 | |
| 136 | foreach(o_target, targetlist) |
| 137 | { |
| 138 | ResTarget *res = (ResTarget *) lfirst(o_target); |
| 139 | |
| 140 | /* |
| 141 | * Check for "something.*". Depending on the complexity of the |
| 142 | * "something", the star could appear as the last field in ColumnRef, |
| 143 | * or as the last indirection item in A_Indirection. |
| 144 | */ |
| 145 | if (expand_star) |
| 146 | { |
| 147 | if (IsA(res->val, ColumnRef)) |
| 148 | { |
| 149 | ColumnRef *cref = (ColumnRef *) res->val; |
| 150 | |
| 151 | if (IsA(llast(cref->fields), A_Star)) |
| 152 | { |
| 153 | /* It is something.*, expand into multiple items */ |
| 154 | p_target = list_concat(p_target, |
| 155 | ExpandColumnRefStar(pstate, |
| 156 | cref, |
| 157 | true)); |
| 158 | continue; |
| 159 | } |
| 160 | } |
| 161 | else if (IsA(res->val, A_Indirection)) |
| 162 | { |
| 163 | A_Indirection *ind = (A_Indirection *) res->val; |
| 164 | |
| 165 | if (IsA(llast(ind->indirection), A_Star)) |
| 166 | { |
| 167 | /* It is something.*, expand into multiple items */ |
| 168 | p_target = list_concat(p_target, |
| 169 | ExpandIndirectionStar(pstate, |
| 170 | ind, |
| 171 | true, |
| 172 | exprKind)); |
| 173 | continue; |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | /* |
| 179 | * Not "something.*", or we want to treat that as a plain whole-row |
no test coverage detected