diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2009-12-15 17:57:48 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2009-12-15 17:57:48 +0000 |
commit | 34d26872ed816b299eef2fa4240d55316697f42d (patch) | |
tree | d7373e29b365c151702c44325f0f5cc9dcc3e17c /src/backend/nodes/nodeFuncs.c | |
parent | 6a6efb964092902bf53965649c3ed78b1868b37e (diff) | |
download | postgresql-34d26872ed816b299eef2fa4240d55316697f42d.tar.gz postgresql-34d26872ed816b299eef2fa4240d55316697f42d.zip |
Support ORDER BY within aggregate function calls, at long last providing a
non-kluge method for controlling the order in which values are fed to an
aggregate function. At the same time eliminate the old implementation
restriction that DISTINCT was only supported for single-argument aggregates.
Possibly release-notable behavioral change: formerly, agg(DISTINCT x)
dropped null values of x unconditionally. Now, it does so only if the
agg transition function is strict; otherwise nulls are treated as DISTINCT
normally would, ie, you get one copy.
Andrew Gierth, reviewed by Hitoshi Harada
Diffstat (limited to 'src/backend/nodes/nodeFuncs.c')
-rw-r--r-- | src/backend/nodes/nodeFuncs.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/backend/nodes/nodeFuncs.c b/src/backend/nodes/nodeFuncs.c index 04a39f17526..d251ef01d18 100644 --- a/src/backend/nodes/nodeFuncs.c +++ b/src/backend/nodes/nodeFuncs.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/nodes/nodeFuncs.c,v 1.43 2009/10/08 02:39:21 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/nodes/nodeFuncs.c,v 1.44 2009/12/15 17:57:46 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -882,6 +882,7 @@ exprLocation(Node *expr) FuncCall *fc = (FuncCall *) expr; /* consider both function name and leftmost arg */ + /* (we assume any ORDER BY nodes must be to right of name) */ loc = leftmostLoc(fc->location, exprLocation((Node *) fc->args)); } @@ -1082,6 +1083,7 @@ expression_tree_walker(Node *node, case T_SetToDefault: case T_CurrentOfExpr: case T_RangeTblRef: + case T_SortGroupClause: /* primitive node types with no expression subnodes */ break; case T_Aggref: @@ -1092,6 +1094,12 @@ expression_tree_walker(Node *node, if (expression_tree_walker((Node *) expr->args, walker, context)) return true; + if (expression_tree_walker((Node *) expr->aggorder, + walker, context)) + return true; + if (expression_tree_walker((Node *) expr->aggdistinct, + walker, context)) + return true; } break; case T_WindowFunc: @@ -1591,6 +1599,7 @@ expression_tree_mutator(Node *node, case T_SetToDefault: case T_CurrentOfExpr: case T_RangeTblRef: + case T_SortGroupClause: return (Node *) copyObject(node); case T_Aggref: { @@ -1599,6 +1608,8 @@ expression_tree_mutator(Node *node, FLATCOPY(newnode, aggref, Aggref); MUTATE(newnode->args, aggref->args, List *); + MUTATE(newnode->aggorder, aggref->aggorder, List *); + MUTATE(newnode->aggdistinct, aggref->aggdistinct, List *); return (Node *) newnode; } break; @@ -2403,6 +2414,8 @@ bool if (walker(fcall->args, context)) return true; + if (walker(fcall->agg_order, context)) + return true; if (walker(fcall->over, context)) return true; /* function name is deemed uninteresting */ |