diff options
author | Noah Misch <noah@leadboat.com> | 2013-07-16 20:15:36 -0400 |
---|---|---|
committer | Noah Misch <noah@leadboat.com> | 2013-07-16 20:15:36 -0400 |
commit | b560ec1b0d7b910ce13edc51ffaafaca72136e3b (patch) | |
tree | ae5d80c94681788fd214efe6d61425089850781e /src/backend/executor/nodeWindowAgg.c | |
parent | 7a8e9f298e7b8158296e1ea72ca8987323c10edf (diff) | |
download | postgresql-b560ec1b0d7b910ce13edc51ffaafaca72136e3b.tar.gz |
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.
Diffstat (limited to 'src/backend/executor/nodeWindowAgg.c')
-rw-r--r-- | src/backend/executor/nodeWindowAgg.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/backend/executor/nodeWindowAgg.c b/src/backend/executor/nodeWindowAgg.c index d9f0e79d10..bbc53361d6 100644 --- a/src/backend/executor/nodeWindowAgg.c +++ b/src/backend/executor/nodeWindowAgg.c @@ -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) |