Generate a reasonable error message when an aggregate function is applied
to an undecorated relation name (cf. example from Ed Loehr, 5/25/00).
This commit is contained in:
parent
cf169e0088
commit
8bba4b4e0e
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.78 2000/04/12 17:15:26 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.79 2000/05/26 03:56:40 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -271,6 +271,7 @@ ParseFuncOrColumn(ParseState *pstate, char *funcname, List *fargs,
|
|||||||
Node *retval;
|
Node *retval;
|
||||||
bool retset;
|
bool retset;
|
||||||
bool must_be_agg = agg_star || agg_distinct;
|
bool must_be_agg = agg_star || agg_distinct;
|
||||||
|
bool could_be_agg;
|
||||||
bool attisset = false;
|
bool attisset = false;
|
||||||
Oid toid = InvalidOid;
|
Oid toid = InvalidOid;
|
||||||
Expr *expr;
|
Expr *expr;
|
||||||
@ -413,28 +414,31 @@ ParseFuncOrColumn(ParseState *pstate, char *funcname, List *fargs,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nargs == 1 || must_be_agg)
|
|
||||||
{
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* See if it's an aggregate.
|
* See if it's an aggregate.
|
||||||
*/
|
*/
|
||||||
Oid basetype;
|
if (must_be_agg)
|
||||||
int ncandidates;
|
{
|
||||||
CandidateList candidates;
|
|
||||||
|
|
||||||
/* We don't presently cope with, eg, foo(DISTINCT x,y) */
|
/* We don't presently cope with, eg, foo(DISTINCT x,y) */
|
||||||
if (nargs != 1)
|
if (nargs != 1)
|
||||||
elog(ERROR, "Aggregate functions may only have one parameter");
|
elog(ERROR, "Aggregate functions may only have one parameter");
|
||||||
|
/* Agg's argument can't be a relation name, either */
|
||||||
/*
|
if (IsA(first_arg, Ident) && ((Ident *) first_arg)->isRel)
|
||||||
* the aggregate COUNT is a special case, ignore its base type.
|
elog(ERROR, "Aggregate functions cannot be applied to relation names");
|
||||||
* Treat it as zero. XXX mighty ugly --- FIXME
|
could_be_agg = true;
|
||||||
*/
|
}
|
||||||
if (strcmp(funcname, "count") == 0)
|
|
||||||
basetype = 0;
|
|
||||||
else
|
else
|
||||||
basetype = exprType(lfirst(fargs));
|
{
|
||||||
|
/* Try to parse as an aggregate if above-mentioned checks are OK */
|
||||||
|
could_be_agg = (nargs == 1) &&
|
||||||
|
!(IsA(first_arg, Ident) && ((Ident *) first_arg)->isRel);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (could_be_agg)
|
||||||
|
{
|
||||||
|
Oid basetype = exprType(lfirst(fargs));
|
||||||
|
int ncandidates;
|
||||||
|
CandidateList candidates;
|
||||||
|
|
||||||
/* try for exact match first... */
|
/* try for exact match first... */
|
||||||
if (SearchSysCacheTuple(AGGNAME,
|
if (SearchSysCacheTuple(AGGNAME,
|
||||||
@ -445,9 +449,18 @@ ParseFuncOrColumn(ParseState *pstate, char *funcname, List *fargs,
|
|||||||
fargs, agg_star, agg_distinct,
|
fargs, agg_star, agg_distinct,
|
||||||
precedence);
|
precedence);
|
||||||
|
|
||||||
|
/* check for aggregate-that-accepts-any-type (eg, COUNT) */
|
||||||
|
if (SearchSysCacheTuple(AGGNAME,
|
||||||
|
PointerGetDatum(funcname),
|
||||||
|
ObjectIdGetDatum(0),
|
||||||
|
0, 0))
|
||||||
|
return (Node *) ParseAgg(pstate, funcname, 0,
|
||||||
|
fargs, agg_star, agg_distinct,
|
||||||
|
precedence);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* No exact match yet, so see if there is another entry in the
|
* No exact match yet, so see if there is another entry in the
|
||||||
* aggregate table which is compatible. - thomas 1998-12-05
|
* aggregate table that is compatible. - thomas 1998-12-05
|
||||||
*/
|
*/
|
||||||
ncandidates = agg_get_candidates(funcname, basetype, &candidates);
|
ncandidates = agg_get_candidates(funcname, basetype, &candidates);
|
||||||
if (ncandidates > 0)
|
if (ncandidates > 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user