mirror of
https://github.com/postgres/postgres.git
synced 2025-11-16 15:02:33 +03:00
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
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/nodes/primnodes.h,v 1.151 2009/10/08 02:39:24 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/include/nodes/primnodes.h,v 1.152 2009/12/15 17:57:47 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -209,16 +209,29 @@ typedef struct Param
|
||||
|
||||
/*
|
||||
* Aggref
|
||||
*
|
||||
* The aggregate's args list is a targetlist, ie, a list of TargetEntry nodes
|
||||
* (before Postgres 8.5 it was just bare expressions). The non-resjunk TLEs
|
||||
* represent the aggregate's regular arguments (if any) and resjunk TLEs can
|
||||
* be added at the end to represent ORDER BY expressions that are not also
|
||||
* arguments. As in a top-level Query, the TLEs can be marked with
|
||||
* ressortgroupref indexes to let them be referenced by SortGroupClause
|
||||
* entries in the aggorder and/or aggdistinct lists. This represents ORDER BY
|
||||
* and DISTINCT operations to be applied to the aggregate input rows before
|
||||
* they are passed to the transition function. The grammar only allows a
|
||||
* simple "DISTINCT" specifier for the arguments, but we use the full
|
||||
* query-level representation to allow more code sharing.
|
||||
*/
|
||||
typedef struct Aggref
|
||||
{
|
||||
Expr xpr;
|
||||
Oid aggfnoid; /* pg_proc Oid of the aggregate */
|
||||
Oid aggtype; /* type Oid of result of the aggregate */
|
||||
List *args; /* arguments to the aggregate */
|
||||
Index agglevelsup; /* > 0 if agg belongs to outer query */
|
||||
List *args; /* arguments and sort expressions */
|
||||
List *aggorder; /* ORDER BY (list of SortGroupClause) */
|
||||
List *aggdistinct; /* DISTINCT (list of SortGroupClause) */
|
||||
bool aggstar; /* TRUE if argument list was really '*' */
|
||||
bool aggdistinct; /* TRUE if it's agg(DISTINCT ...) */
|
||||
Index agglevelsup; /* > 0 if agg belongs to outer query */
|
||||
int location; /* token location, or -1 if unknown */
|
||||
} Aggref;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user