* colNameToVar * Search for an unqualified column name. * If found, return the appropriate Var node (or expression). * If not found, return NULL. If the name proves ambiguous, raise error. * If localonly is true, only names in the innermost query are considered. */
| 874 | * If localonly is true, only names in the innermost query are considered. |
| 875 | */ |
| 876 | Node * |
| 877 | colNameToVar(ParseState *pstate, const char *colname, bool localonly, |
| 878 | int location) |
| 879 | { |
| 880 | Node *result = NULL; |
| 881 | int sublevels_up = 0; |
| 882 | ParseState *orig_pstate = pstate; |
| 883 | |
| 884 | while (pstate != NULL) |
| 885 | { |
| 886 | ListCell *l; |
| 887 | |
| 888 | foreach(l, pstate->p_namespace) |
| 889 | { |
| 890 | ParseNamespaceItem *nsitem = (ParseNamespaceItem *) lfirst(l); |
| 891 | Node *newresult; |
| 892 | |
| 893 | /* Ignore table-only items */ |
| 894 | if (!nsitem->p_cols_visible) |
| 895 | continue; |
| 896 | /* If not inside LATERAL, ignore lateral-only items */ |
| 897 | if (nsitem->p_lateral_only && !pstate->p_lateral_active) |
| 898 | continue; |
| 899 | |
| 900 | /* use orig_pstate here for consistency with other callers */ |
| 901 | newresult = scanNSItemForColumn(orig_pstate, nsitem, sublevels_up, |
| 902 | colname, location); |
| 903 | |
| 904 | if (newresult) |
| 905 | { |
| 906 | if (result) |
| 907 | ereport(ERROR, |
| 908 | (errcode(ERRCODE_AMBIGUOUS_COLUMN), |
| 909 | errmsg("column reference \"%s\" is ambiguous", |
| 910 | colname), |
| 911 | parser_errposition(pstate, location))); |
| 912 | check_lateral_ref_ok(pstate, nsitem, location); |
| 913 | result = newresult; |
| 914 | } |
| 915 | } |
| 916 | |
| 917 | if (result != NULL || localonly) |
| 918 | break; /* found, or don't want to look at parent */ |
| 919 | |
| 920 | pstate = pstate->parentParseState; |
| 921 | sublevels_up++; |
| 922 | } |
| 923 | |
| 924 | return result; |
| 925 | } |
| 926 | |
| 927 | /* |
| 928 | * searchRangeTableForCol |
no test coverage detected