* Search the query's table namespace for a relation item matching the * given relation OID. Return the nsitem if a unique match, or NULL * if no match. Raise error if multiple matches. * * See the comments for refnameNamespaceItem to understand why this * acts the way it does. */
| 223 | * acts the way it does. |
| 224 | */ |
| 225 | static ParseNamespaceItem * |
| 226 | scanNameSpaceForRelid(ParseState *pstate, Oid relid, int location) |
| 227 | { |
| 228 | ParseNamespaceItem *result = NULL; |
| 229 | ListCell *l; |
| 230 | |
| 231 | foreach(l, pstate->p_namespace) |
| 232 | { |
| 233 | ParseNamespaceItem *nsitem = (ParseNamespaceItem *) lfirst(l); |
| 234 | RangeTblEntry *rte = nsitem->p_rte; |
| 235 | |
| 236 | /* Ignore columns-only items */ |
| 237 | if (!nsitem->p_rel_visible) |
| 238 | continue; |
| 239 | /* If not inside LATERAL, ignore lateral-only items */ |
| 240 | if (nsitem->p_lateral_only && !pstate->p_lateral_active) |
| 241 | continue; |
| 242 | |
| 243 | /* yes, the test for alias == NULL should be there... */ |
| 244 | if (rte->rtekind == RTE_RELATION && |
| 245 | rte->relid == relid && |
| 246 | rte->alias == NULL) |
| 247 | { |
| 248 | if (result) |
| 249 | ereport(ERROR, |
| 250 | (errcode(ERRCODE_AMBIGUOUS_ALIAS), |
| 251 | errmsg("table reference %u is ambiguous", |
| 252 | relid), |
| 253 | parser_errposition(pstate, location))); |
| 254 | check_lateral_ref_ok(pstate, nsitem, location); |
| 255 | result = nsitem; |
| 256 | } |
| 257 | } |
| 258 | return result; |
| 259 | } |
| 260 | |
| 261 | /* |
| 262 | * Search the query's CTE namespace for a CTE matching the given unqualified |
no test coverage detected