* plpgsql_post_column_ref parser callback after parsing a ColumnRef */
| 1124 | * plpgsql_post_column_ref parser callback after parsing a ColumnRef |
| 1125 | */ |
| 1126 | static Node * |
| 1127 | plpgsql_post_column_ref(ParseState *pstate, ColumnRef *cref, Node *var) |
| 1128 | { |
| 1129 | PLpgSQL_expr *expr = (PLpgSQL_expr *) pstate->p_ref_hook_state; |
| 1130 | Node *myvar; |
| 1131 | |
| 1132 | if (expr->func->resolve_option == PLPGSQL_RESOLVE_VARIABLE) |
| 1133 | return NULL; /* we already found there's no match */ |
| 1134 | |
| 1135 | if (expr->func->resolve_option == PLPGSQL_RESOLVE_COLUMN && var != NULL) |
| 1136 | return NULL; /* there's a table column, prefer that */ |
| 1137 | |
| 1138 | /* |
| 1139 | * If we find a record/row variable but can't match a field name, throw |
| 1140 | * error if there was no core resolution for the ColumnRef either. In |
| 1141 | * that situation, the reference is inevitably going to fail, and |
| 1142 | * complaining about the record/row variable is likely to be more on-point |
| 1143 | * than the core parser's error message. (It's too bad we don't have |
| 1144 | * access to transformColumnRef's internal crerr state here, as in case of |
| 1145 | * a conflict with a table name this could still be less than the most |
| 1146 | * helpful error message possible.) |
| 1147 | */ |
| 1148 | myvar = resolve_column_ref(pstate, expr, cref, (var == NULL)); |
| 1149 | |
| 1150 | if (myvar != NULL && var != NULL) |
| 1151 | { |
| 1152 | /* |
| 1153 | * We could leave it to the core parser to throw this error, but we |
| 1154 | * can add a more useful detail message than the core could. |
| 1155 | */ |
| 1156 | ereport(ERROR, |
| 1157 | (errcode(ERRCODE_AMBIGUOUS_COLUMN), |
| 1158 | errmsg("column reference \"%s\" is ambiguous", |
| 1159 | NameListToString(cref->fields)), |
| 1160 | errdetail("It could refer to either a PL/pgSQL variable or a table column."), |
| 1161 | parser_errposition(pstate, cref->location))); |
| 1162 | } |
| 1163 | |
| 1164 | return myvar; |
| 1165 | } |
| 1166 | |
| 1167 | /* |
| 1168 | * plpgsql_param_ref parser callback for ParamRefs ($n symbols) |
nothing calls this directly
no test coverage detected