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

Function checkNameSpaceConflicts

src/backend/parser/parse_relation.c:422–458  ·  view source on GitHub ↗

* Check for relation-name conflicts between two namespace lists. * Raise an error if any is found. * * Note: we assume that each given argument does not contain conflicts * itself; we just want to know if the two can be merged together. * * Per SQL, two alias-less plain relation RTEs do not conflict even if * they have the same eref->aliasname (ie, same relation name), if they * are for di

Source from the content-addressed store, hash-verified

420 * columns-only items should be ignored.
421 */
422void
423checkNameSpaceConflicts(ParseState *pstate, List *namespace1,
424 List *namespace2)
425{
426 ListCell *l1;
427
428 foreach(l1, namespace1)
429 {
430 ParseNamespaceItem *nsitem1 = (ParseNamespaceItem *) lfirst(l1);
431 RangeTblEntry *rte1 = nsitem1->p_rte;
432 const char *aliasname1 = nsitem1->p_names->aliasname;
433 ListCell *l2;
434
435 if (!nsitem1->p_rel_visible)
436 continue;
437
438 foreach(l2, namespace2)
439 {
440 ParseNamespaceItem *nsitem2 = (ParseNamespaceItem *) lfirst(l2);
441 RangeTblEntry *rte2 = nsitem2->p_rte;
442 const char *aliasname2 = nsitem2->p_names->aliasname;
443
444 if (!nsitem2->p_rel_visible)
445 continue;
446 if (strcmp(aliasname2, aliasname1) != 0)
447 continue; /* definitely no conflict */
448 if (rte1->rtekind == RTE_RELATION && rte1->alias == NULL &&
449 rte2->rtekind == RTE_RELATION && rte2->alias == NULL &&
450 rte1->relid != rte2->relid)
451 continue; /* no conflict per SQL rule */
452 ereport(ERROR,
453 (errcode(ERRCODE_DUPLICATE_ALIAS),
454 errmsg("table name \"%s\" specified more than once",
455 aliasname1)));
456 }
457 }
458}
459
460/*
461 * Complain if a namespace item is currently disallowed as a LATERAL reference.

Callers 2

transformFromClauseFunction · 0.85
transformFromClauseItemFunction · 0.85

Calls 3

foreachFunction · 0.50
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected