Skip to content

Commit 331c3c2

Browse files
committed
Add a very specific hint for the case that we're unable to locate a function
matching a call like f(x, ORDER BY y,z). It could be that what the user really wants is f(x,z ORDER BY y). We now have pretty conclusive evidence that many people won't understand this problem without concrete guidance, so give it to them. Per further discussion of the string_agg() problem.
1 parent 5f5f193 commit 331c3c2

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/backend/parser/parse_func.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/parser/parse_func.c,v 1.224.2.1 2010/07/29 23:16:41 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/parser/parse_func.c,v 1.224.2.2 2010/08/05 21:45:45 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -284,6 +284,19 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
284284
errhint("Could not choose a best candidate function. "
285285
"You might need to add explicit type casts."),
286286
parser_errposition(pstate, location)));
287+
else if (list_length(agg_order) > 1)
288+
{
289+
/* It's agg(x, ORDER BY y,z) ... perhaps misplaced ORDER BY */
290+
ereport(ERROR,
291+
(errcode(ERRCODE_UNDEFINED_FUNCTION),
292+
errmsg("function %s does not exist",
293+
func_signature_string(funcname, nargs, argnames,
294+
actual_arg_types)),
295+
errhint("No aggregate function matches the given name and argument types. "
296+
"Perhaps you misplaced ORDER BY; ORDER BY must appear "
297+
"after all regular arguments of the aggregate."),
298+
parser_errposition(pstate, location)));
299+
}
287300
else
288301
ereport(ERROR,
289302
(errcode(ERRCODE_UNDEFINED_FUNCTION),

0 commit comments

Comments
 (0)