mirror of
https://github.com/postgres/postgres.git
synced 2025-07-05 07:21:24 +03:00
Implement the FILTER clause for aggregate function calls.
This is SQL-standard with a few extensions, namely support for subqueries and outer references in clause expressions. catversion bump due to change in Aggref and WindowFunc. David Fetter, reviewed by Dean Rasheed.
This commit is contained in:
@ -227,9 +227,23 @@ advance_windowaggregate(WindowAggState *winstate,
|
||||
int i;
|
||||
MemoryContext oldContext;
|
||||
ExprContext *econtext = winstate->tmpcontext;
|
||||
ExprState *filter = wfuncstate->aggfilter;
|
||||
|
||||
oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
|
||||
|
||||
/* Skip anything FILTERed out */
|
||||
if (filter)
|
||||
{
|
||||
bool isnull;
|
||||
Datum res = ExecEvalExpr(filter, econtext, &isnull, NULL);
|
||||
|
||||
if (isnull || !DatumGetBool(res))
|
||||
{
|
||||
MemoryContextSwitchTo(oldContext);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* We start from 1, since the 0th arg will be the transition value */
|
||||
i = 1;
|
||||
foreach(arg, wfuncstate->args)
|
||||
|
Reference in New Issue
Block a user