MCPcopy Create free account
hub / github.com/apache/cloudberry / scanNameSpaceForRefname

Function scanNameSpaceForRefname

src/backend/parser/parse_relation.c:185–215  ·  view source on GitHub ↗

* 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,

Source from the content-addressed store, hash-verified

183 * reference to "x".
184 */
185static ParseNamespaceItem *
186scanNameSpaceForRefname(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

Callers 1

refnameNamespaceItemFunction · 0.85

Calls 5

parser_errpositionFunction · 0.85
check_lateral_ref_okFunction · 0.85
foreachFunction · 0.50
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected