1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-09-09 21:09:38 +03:00

Experimental implementation of FILTER clause for aggregate functions.

FossilOrigin-Name: 1f1ae2d6ac8dcbb62e5aa3dc17bc67d559cb565fc0d0a8c00a596075d35f8130
This commit is contained in:
dan
2019-07-02 11:56:47 +00:00
parent 00a6153faf
commit 6ba7ab0d25
12 changed files with 342 additions and 45 deletions

View File

@@ -849,6 +849,12 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
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 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
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 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
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;