mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Support ordered-set (WITHIN GROUP) aggregates.
This patch introduces generic support for ordered-set and hypothetical-set aggregate functions, as well as implementations of the instances defined in SQL:2008 (percentile_cont(), percentile_disc(), rank(), dense_rank(), percent_rank(), cume_dist()). We also added mode() though it is not in the spec, as well as versions of percentile_cont() and percentile_disc() that can compute multiple percentile values in one pass over the data. Unlike the original submission, this patch puts full control of the sorting process in the hands of the aggregate's support functions. To allow the support functions to find out how they're supposed to sort, a new API function AggGetAggref() is added to nodeAgg.c. This allows retrieval of the aggregate call's Aggref node, which may have other uses beyond the immediate need. There is also support for ordered-set aggregates to install cleanup callback functions, so that they can be sure that infrastructure such as tuplesort objects gets cleaned up. In passing, make some fixes in the recently-added support for variadic aggregates, and make some editorial adjustments in the recent FILTER additions for aggregates. Also, simplify use of IsBinaryCoercible() by allowing it to succeed whenever the target type is ANY or ANYELEMENT. It was inconsistent that it dealt with other polymorphic target types but not these. Atri Sharma and Andrew Gierth; reviewed by Pavel Stehule and Vik Fearing, and rather heavily editorialized upon by Tom Lane
This commit is contained in:
@@ -30,7 +30,7 @@ ALTER EXTENSION <replaceable class="PARAMETER">name</replaceable> DROP <replacea
|
||||
|
||||
<phrase>where <replaceable class="PARAMETER">member_object</replaceable> is:</phrase>
|
||||
|
||||
AGGREGATE <replaceable class="PARAMETER">agg_name</replaceable> ( [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">agg_type</replaceable> [, ...] ) |
|
||||
AGGREGATE <replaceable class="PARAMETER">aggregate_name</replaceable> ( <replaceable>aggregate_signature</replaceable> ) |
|
||||
CAST (<replaceable>source_type</replaceable> AS <replaceable>target_type</replaceable>) |
|
||||
COLLATION <replaceable class="PARAMETER">object_name</replaceable> |
|
||||
CONVERSION <replaceable class="PARAMETER">object_name</replaceable> |
|
||||
@@ -54,6 +54,12 @@ ALTER EXTENSION <replaceable class="PARAMETER">name</replaceable> DROP <replacea
|
||||
TEXT SEARCH TEMPLATE <replaceable class="PARAMETER">object_name</replaceable> |
|
||||
TYPE <replaceable class="PARAMETER">object_name</replaceable> |
|
||||
VIEW <replaceable class="PARAMETER">object_name</replaceable>
|
||||
|
||||
<phrase>and <replaceable>aggregate_signature</replaceable> is:</phrase>
|
||||
|
||||
* |
|
||||
[ <replaceable>argmode</replaceable> ] [ <replaceable>argname</replaceable> ] <replaceable>argtype</replaceable> [ , ... ] |
|
||||
[ [ <replaceable>argmode</replaceable> ] [ <replaceable>argname</replaceable> ] <replaceable>argtype</replaceable> [ , ... ] ] ORDER BY [ <replaceable>argmode</replaceable> ] [ <replaceable>argname</replaceable> ] <replaceable>argtype</replaceable> [ , ... ]
|
||||
</synopsis>
|
||||
</refsynopsisdiv>
|
||||
|
||||
@@ -159,7 +165,7 @@ ALTER EXTENSION <replaceable class="PARAMETER">name</replaceable> DROP <replacea
|
||||
|
||||
<varlistentry>
|
||||
<term><replaceable class="parameter">object_name</replaceable></term>
|
||||
<term><replaceable class="parameter">agg_name</replaceable></term>
|
||||
<term><replaceable class="parameter">aggregate_name</replaceable></term>
|
||||
<term><replaceable class="parameter">function_name</replaceable></term>
|
||||
<term><replaceable class="parameter">operator_name</replaceable></term>
|
||||
<listitem>
|
||||
@@ -173,17 +179,6 @@ ALTER EXTENSION <replaceable class="PARAMETER">name</replaceable> DROP <replacea
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><replaceable class="parameter">agg_type</replaceable></term>
|
||||
<listitem>
|
||||
<para>
|
||||
An input data type on which the aggregate function operates.
|
||||
To reference a zero-argument aggregate function, write <literal>*</>
|
||||
in place of the list of argument specifications.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><replaceable>source_type</replaceable></term>
|
||||
<listitem>
|
||||
@@ -207,7 +202,8 @@ ALTER EXTENSION <replaceable class="PARAMETER">name</replaceable> DROP <replacea
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
The mode of a function argument: <literal>IN</>, <literal>OUT</>,
|
||||
The mode of a function or aggregate
|
||||
argument: <literal>IN</>, <literal>OUT</>,
|
||||
<literal>INOUT</>, or <literal>VARIADIC</>.
|
||||
If omitted, the default is <literal>IN</>.
|
||||
Note that <command>ALTER EXTENSION</command> does not actually pay
|
||||
@@ -224,7 +220,7 @@ ALTER EXTENSION <replaceable class="PARAMETER">name</replaceable> DROP <replacea
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
The name of a function argument.
|
||||
The name of a function or aggregate argument.
|
||||
Note that <command>ALTER EXTENSION</command> does not actually pay
|
||||
any attention to argument names, since only the argument data
|
||||
types are needed to determine the function's identity.
|
||||
@@ -237,8 +233,7 @@ ALTER EXTENSION <replaceable class="PARAMETER">name</replaceable> DROP <replacea
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
The data type(s) of the function's arguments (optionally
|
||||
schema-qualified), if any.
|
||||
The data type of a function or aggregate argument.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
Reference in New Issue
Block a user