Experimental implementation of FILTER clause for aggregate functions.
FossilOrigin-Name: 1f1ae2d6ac8dcbb62e5aa3dc17bc67d559cb565fc0d0a8c00a596075d35f8130
diff --git a/src/resolve.c b/src/resolve.c
index 8dac077..0a8aff5 100644
--- a/src/resolve.c
+++ b/src/resolve.c
@@ -849,6 +849,12 @@
sqlite3ErrorMsg(pParse, "misuse of %s function %.*s()",zType,nId,zId);
pNC->nErr++;
is_agg = 0;
+ }else if( is_agg==0 && ExprHasProperty(pExpr, EP_Filter) ){
+ sqlite3ErrorMsg(pParse,
+ "filter clause may not be used with non-aggregate %.*s()",
+ nId, zId
+ );
+ pNC->nErr++;
}
#else
if( (is_agg && (pNC->ncFlags & NC_AllowAgg)==0) ){
@@ -883,7 +889,7 @@
sqlite3WalkExprList(pWalker, pList);
if( is_agg ){
#ifndef SQLITE_OMIT_WINDOWFUNC
- if( pExpr->y.pWin ){
+ if( ExprHasProperty(pExpr, EP_WinFunc) ){
Select *pSel = pNC->pWinSelect;
if( IN_RENAME_OBJECT==0 ){
sqlite3WindowUpdate(pParse, pSel->pWinDefn, pExpr->y.pWin, pDef);
@@ -904,6 +910,9 @@
NameContext *pNC2 = pNC;
pExpr->op = TK_AGG_FUNCTION;
pExpr->op2 = 0;
+#ifndef SQLITE_OMIT_WINDOWFUNC
+ sqlite3WalkExpr(pWalker, pExpr->y.pFilter);
+#endif
while( pNC2 && !sqlite3FunctionUsesThisSrc(pExpr, pNC2->pSrcList) ){
pExpr->op2++;
pNC2 = pNC2->pNext;