* Search the query's CTE namespace for a CTE matching the given unqualified * refname. Return the CTE (and its levelsup count) if a match, or NULL * if no match. We need not worry about multiple matches, since parse_cte.c * rejects WITH lists containing duplicate CTE names. */
| 265 | * rejects WITH lists containing duplicate CTE names. |
| 266 | */ |
| 267 | CommonTableExpr * |
| 268 | scanNameSpaceForCTE(ParseState *pstate, const char *refname, |
| 269 | Index *ctelevelsup) |
| 270 | { |
| 271 | Index levelsup; |
| 272 | |
| 273 | for (levelsup = 0; |
| 274 | pstate != NULL; |
| 275 | pstate = pstate->parentParseState, levelsup++) |
| 276 | { |
| 277 | ListCell *lc; |
| 278 | |
| 279 | foreach(lc, pstate->p_ctenamespace) |
| 280 | { |
| 281 | CommonTableExpr *cte = (CommonTableExpr *) lfirst(lc); |
| 282 | |
| 283 | if (strcmp(cte->ctename, refname) == 0) |
| 284 | { |
| 285 | *ctelevelsup = levelsup; |
| 286 | return cte; |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | return NULL; |
| 291 | } |
| 292 | |
| 293 | /* |
| 294 | * Search for a possible "future CTE", that is one that is not yet in scope |
no test coverage detected