|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.133 2002/08/02 18:15:07 tgl Exp $ |
| 11 | + * $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.134 2002/08/08 01:44:30 tgl Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -51,6 +51,8 @@ static int match_argtypes(int nargs,
|
51 | 51 | static FieldSelect *setup_field_select(Node *input, char *attname, Oid relid);
|
52 | 52 | static FuncCandidateList func_select_candidate(int nargs, Oid *input_typeids,
|
53 | 53 | FuncCandidateList candidates);
|
| 54 | +static void unknown_attribute(const char *schemaname, const char *relname, |
| 55 | + const char *attname); |
54 | 56 |
|
55 | 57 |
|
56 | 58 | /*
|
@@ -80,7 +82,6 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
|
80 | 82 | Oid funcid;
|
81 | 83 | List *i;
|
82 | 84 | Node *first_arg = NULL;
|
83 |
| - char *refname; |
84 | 85 | int nargs = length(fargs);
|
85 | 86 | int argn;
|
86 | 87 | Oid oid_array[FUNC_MAX_ARGS];
|
@@ -121,10 +122,11 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
|
121 | 122 | if (IsA(first_arg, RangeVar))
|
122 | 123 | {
|
123 | 124 | /* First arg is a relation. This could be a projection. */
|
124 |
| - refname = ((RangeVar *) first_arg)->relname; |
125 |
| - |
126 |
| - /* XXX WRONG: ignores possible qualification of argument */ |
127 |
| - retval = qualifiedNameToVar(pstate, refname, cname, true); |
| 125 | + retval = qualifiedNameToVar(pstate, |
| 126 | + ((RangeVar *) first_arg)->schemaname, |
| 127 | + ((RangeVar *) first_arg)->relname, |
| 128 | + cname, |
| 129 | + true); |
128 | 130 | if (retval)
|
129 | 131 | return retval;
|
130 | 132 | }
|
@@ -156,16 +158,19 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
|
156 | 158 |
|
157 | 159 | if (IsA(arg, RangeVar))
|
158 | 160 | {
|
| 161 | + char *schemaname; |
| 162 | + char *relname; |
159 | 163 | RangeTblEntry *rte;
|
160 | 164 | int vnum;
|
161 | 165 | int sublevels_up;
|
162 | 166 |
|
163 | 167 | /*
|
164 |
| - * a relation |
| 168 | + * a relation: look it up in the range table, or add if needed |
165 | 169 | */
|
166 |
| - refname = ((RangeVar *) arg)->relname; |
| 170 | + schemaname = ((RangeVar *) arg)->schemaname; |
| 171 | + relname = ((RangeVar *) arg)->relname; |
167 | 172 |
|
168 |
| - rte = refnameRangeTblEntry(pstate, refname, |
| 173 | + rte = refnameRangeTblEntry(pstate, schemaname, relname, |
169 | 174 | &sublevels_up);
|
170 | 175 |
|
171 | 176 | if (rte == NULL)
|
@@ -199,11 +204,11 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
|
199 | 204 | * named tuple type
|
200 | 205 | */
|
201 | 206 | if (is_column)
|
202 |
| - elog(ERROR, "No such attribute %s.%s", |
203 |
| - refname, strVal(lfirst(funcname))); |
| 207 | + unknown_attribute(schemaname, relname, |
| 208 | + strVal(lfirst(funcname))); |
204 | 209 | else
|
205 | 210 | elog(ERROR, "Cannot pass result of sub-select or join %s to a function",
|
206 |
| - refname); |
| 211 | + relname); |
207 | 212 | toid = InvalidOid; /* keep compiler quiet */
|
208 | 213 | break;
|
209 | 214 | }
|
@@ -268,8 +273,9 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
|
268 | 273 |
|
269 | 274 | Assert(nargs == 1);
|
270 | 275 | if (IsA(first_arg, RangeVar))
|
271 |
| - elog(ERROR, "No such attribute %s.%s", |
272 |
| - ((RangeVar *) first_arg)->relname, colname); |
| 276 | + unknown_attribute(((RangeVar *) first_arg)->schemaname, |
| 277 | + ((RangeVar *) first_arg)->relname, |
| 278 | + colname); |
273 | 279 | relTypeId = exprType(first_arg);
|
274 | 280 | if (!ISCOMPLEX(relTypeId))
|
275 | 281 | elog(ERROR, "Attribute notation .%s applied to type %s, which is not a complex type",
|
@@ -1225,6 +1231,21 @@ ParseComplexProjection(ParseState *pstate,
|
1225 | 1231 | return (Node *) fselect;
|
1226 | 1232 | }
|
1227 | 1233 |
|
| 1234 | +/* |
| 1235 | + * Simple helper routine for delivering "No such attribute" error message |
| 1236 | + */ |
| 1237 | +static void |
| 1238 | +unknown_attribute(const char *schemaname, const char *relname, |
| 1239 | + const char *attname) |
| 1240 | +{ |
| 1241 | + if (schemaname) |
| 1242 | + elog(ERROR, "No such attribute %s.%s.%s", |
| 1243 | + schemaname, relname, attname); |
| 1244 | + else |
| 1245 | + elog(ERROR, "No such attribute %s.%s", |
| 1246 | + relname, attname); |
| 1247 | +} |
| 1248 | + |
1228 | 1249 | /*
|
1229 | 1250 | * Error message when function lookup fails that gives details of the
|
1230 | 1251 | * argument types
|
|
0 commit comments