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/nodeAgg.c | |
parent | 7a8e9f298e7b8158296e1ea72ca8987323c10edf (diff) | |
download | postgresql-b560ec1b0d7b910ce13edc51ffaafaca72136e3b.tar.gz postgresql-b560ec1b0d7b910ce13edc51ffaafaca72136e3b.zip |
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/nodeAgg.c')
-rw-r--r-- | src/backend/executor/nodeAgg.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c index c741131b257..7a0c2541cbe 100644 --- a/src/backend/executor/nodeAgg.c +++ b/src/backend/executor/nodeAgg.c @@ -484,10 +484,23 @@ advance_aggregates(AggState *aggstate, AggStatePerGroup pergroup) { AggStatePerAgg peraggstate = &aggstate->peragg[aggno]; AggStatePerGroup pergroupstate = &pergroup[aggno]; + ExprState *filter = peraggstate->aggrefstate->aggfilter; int nargs = peraggstate->numArguments; int i; TupleTableSlot *slot; + /* Skip anything FILTERed out */ + if (filter) + { + bool isnull; + Datum res; + + res = ExecEvalExprSwitchContext(filter, aggstate->tmpcontext, + &isnull, NULL); + if (isnull || !DatumGetBool(res)) + continue; + } + /* Evaluate the current input expressions for this aggregate */ slot = ExecProject(peraggstate->evalproj, NULL); |