1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-01 06:27:03 +03:00

Allow an aggregate function in the HAVING clause even if no aggregates appear

in the result set.  Ticket #187. (CVS 793)

FossilOrigin-Name: 33c6fd6b3dc271fa1f2d4500b4f76c736accefce
This commit is contained in:
drh
2002-12-03 02:34:49 +00:00
parent 174b619591
commit c66c5a266b
4 changed files with 32 additions and 24 deletions

View File

@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
** $Id: select.c,v 1.116 2002/12/03 02:22:52 drh Exp $
** $Id: select.c,v 1.117 2002/12/03 02:34:50 drh Exp $
*/
#include "sqliteInt.h"
@ -1870,6 +1870,20 @@ int sqliteSelect(
}
sqliteOracle8JoinFixup(base, pTabList, pWhere);
}
if( pHaving ){
if( pGroupBy==0 ){
sqliteSetString(&pParse->zErrMsg, "a GROUP BY clause is required "
"before HAVING", 0);
pParse->nErr++;
goto select_end;
}
if( sqliteExprResolveIds(pParse, base, pTabList, pEList, pHaving) ){
goto select_end;
}
if( sqliteExprCheck(pParse, pHaving, 1, &isAgg) ){
goto select_end;
}
}
if( pOrderBy ){
for(i=0; i<pOrderBy->nExpr; i++){
Expr *pE = pOrderBy->a[i].pExpr;
@ -1916,20 +1930,6 @@ int sqliteSelect(
}
}
}
if( pHaving ){
if( pGroupBy==0 ){
sqliteSetString(&pParse->zErrMsg, "a GROUP BY clause is required "
"before HAVING", 0);
pParse->nErr++;
goto select_end;
}
if( sqliteExprResolveIds(pParse, base, pTabList, pEList, pHaving) ){
goto select_end;
}
if( sqliteExprCheck(pParse, pHaving, isAgg, 0) ){
goto select_end;
}
}
/* Check for the special case of a min() or max() function by itself
** in the result set.