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

Function scanRTEForColumn

src/backend/parser/parse_relation.c:782–867  ·  view source on GitHub ↗

* scanRTEForColumn * Search the column names of a single RTE for the given name. * If found, return the attnum (possibly negative, for a system column); * else return InvalidAttrNumber. * If the name proves ambiguous within this RTE, raise error. * * Actually, we only search the names listed in "eref". This can be either * rte->eref, in which case we are indeed searching all the co

Source from the content-addressed store, hash-verified

780 * working to complain about an invalid name, we've already eliminated that.
781 */
782static int
783scanRTEForColumn(ParseState *pstate, RangeTblEntry *rte,
784 Alias *eref,
785 const char *colname, int location,
786 int fuzzy_rte_penalty,
787 FuzzyAttrMatchState *fuzzystate)
788{
789 int result = InvalidAttrNumber;
790 int attnum = 0;
791 ListCell *c;
792
793 /*
794 * Scan the user column names (or aliases) for a match. Complain if
795 * multiple matches.
796 *
797 * Note: eref->colnames may include entries for dropped columns, but those
798 * will be empty strings that cannot match any legal SQL identifier, so we
799 * don't bother to test for that case here.
800 *
801 * Should this somehow go wrong and we try to access a dropped column,
802 * we'll still catch it by virtue of the check in scanNSItemForColumn().
803 * Callers interested in finding match with shortest distance need to
804 * defend against this directly, though.
805 */
806 foreach(c, eref->colnames)
807 {
808 const char *attcolname = strVal(lfirst(c));
809
810 attnum++;
811 if (strcmp(attcolname, colname) == 0)
812 {
813 if (result)
814 ereport(ERROR,
815 (errcode(ERRCODE_AMBIGUOUS_COLUMN),
816 errmsg("column reference \"%s\" is ambiguous",
817 colname),
818 parser_errposition(pstate, location)));
819 result = attnum;
820 }
821
822 /* Update fuzzy match state, if provided. */
823 if (fuzzystate != NULL)
824 updateFuzzyAttrMatchState(fuzzy_rte_penalty, fuzzystate,
825 rte, attcolname, colname, attnum);
826 }
827
828 /*
829 * If we have a unique match, return it. Note that this allows a user
830 * alias to override a system column name (such as OID) without error.
831 */
832 if (result)
833 return result;
834
835 /*
836 * If the RTE represents a real relation, consider system column names.
837 * Composites are only used for pseudo-relations like ON CONFLICT's
838 * excluded.
839 */

Callers 2

scanNSItemForColumnFunction · 0.85
searchRangeTableForColFunction · 0.85

Calls 10

parser_errpositionFunction · 0.85
GpPolicyIsReplicatedFunction · 0.85
GpPolicyFetchFunction · 0.85
specialAttNumFunction · 0.85
ObjectIdGetDatumFunction · 0.85
Int16GetDatumFunction · 0.85
foreachFunction · 0.50
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected