* Search the query's table namespace for an item matching the * given unqualified refname. Return the nsitem if a unique match, or NULL * if no match. Raise error if multiple matches. * * Note: it might seem that we shouldn't have to worry about the possibility * of multiple matches; after all, the SQL standard disallows duplicate table * aliases within a given SELECT level. Historically,
| 183 | * reference to "x". |
| 184 | */ |
| 185 | static ParseNamespaceItem * |
| 186 | scanNameSpaceForRefname(ParseState *pstate, const char *refname, int location) |
| 187 | { |
| 188 | ParseNamespaceItem *result = NULL; |
| 189 | ListCell *l; |
| 190 | |
| 191 | foreach(l, pstate->p_namespace) |
| 192 | { |
| 193 | ParseNamespaceItem *nsitem = (ParseNamespaceItem *) lfirst(l); |
| 194 | |
| 195 | /* Ignore columns-only items */ |
| 196 | if (!nsitem->p_rel_visible) |
| 197 | continue; |
| 198 | /* If not inside LATERAL, ignore lateral-only items */ |
| 199 | if (nsitem->p_lateral_only && !pstate->p_lateral_active) |
| 200 | continue; |
| 201 | |
| 202 | if (strcmp(nsitem->p_names->aliasname, refname) == 0) |
| 203 | { |
| 204 | if (result) |
| 205 | ereport(ERROR, |
| 206 | (errcode(ERRCODE_AMBIGUOUS_ALIAS), |
| 207 | errmsg("table reference \"%s\" is ambiguous", |
| 208 | refname), |
| 209 | parser_errposition(pstate, location))); |
| 210 | check_lateral_ref_ok(pstate, nsitem, location); |
| 211 | result = nsitem; |
| 212 | } |
| 213 | } |
| 214 | return result; |
| 215 | } |
| 216 | |
| 217 | /* |
| 218 | * Search the query's table namespace for a relation item matching the |
no test coverage detected