mirror of
https://github.com/postgres/postgres.git
synced 2025-12-22 17:42:17 +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:
@@ -21,12 +21,15 @@ PostgreSQL documentation
|
||||
|
||||
<refsynopsisdiv>
|
||||
<synopsis>
|
||||
ALTER AGGREGATE <replaceable>name</replaceable> ( [ <replaceable>argmode</replaceable> ] [ <replaceable>arg_name</replaceable> ] <replaceable>arg_data_type</replaceable> [ , ... ] )
|
||||
RENAME TO <replaceable>new_name</replaceable>
|
||||
ALTER AGGREGATE <replaceable>name</replaceable> ( [ <replaceable>argmode</replaceable> ] [ <replaceable>arg_name</replaceable> ] <replaceable>arg_data_type</replaceable> [ , ... ] )
|
||||
OWNER TO <replaceable>new_owner</replaceable>
|
||||
ALTER AGGREGATE <replaceable>name</replaceable> ( [ <replaceable>argmode</replaceable> ] [ <replaceable>arg_name</replaceable> ] <replaceable>arg_data_type</replaceable> [ , ... ] )
|
||||
SET SCHEMA <replaceable>new_schema</replaceable>
|
||||
ALTER AGGREGATE <replaceable>name</replaceable> ( <replaceable>aggregate_signature</replaceable> ) RENAME TO <replaceable>new_name</replaceable>
|
||||
ALTER AGGREGATE <replaceable>name</replaceable> ( <replaceable>aggregate_signature</replaceable> ) OWNER TO <replaceable>new_owner</replaceable>
|
||||
ALTER AGGREGATE <replaceable>name</replaceable> ( <replaceable>aggregate_signature</replaceable> ) SET SCHEMA <replaceable>new_schema</replaceable>
|
||||
|
||||
<phrase>where <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>
|
||||
|
||||
@@ -76,7 +79,7 @@ ALTER AGGREGATE <replaceable>name</replaceable> ( [ <replaceable>argmode</replac
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><replaceable class="parameter">arg_name</replaceable></term>
|
||||
<term><replaceable class="parameter">argname</replaceable></term>
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
@@ -89,12 +92,15 @@ ALTER AGGREGATE <replaceable>name</replaceable> ( [ <replaceable>argmode</replac
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><replaceable class="parameter">arg_data_type</replaceable></term>
|
||||
<term><replaceable class="parameter">argtype</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.
|
||||
To reference an ordered-set aggregate function, write
|
||||
<literal>ORDER BY</> between the direct and aggregated argument
|
||||
specifications.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@@ -128,6 +134,21 @@ ALTER AGGREGATE <replaceable>name</replaceable> ( [ <replaceable>argmode</replac
|
||||
</variablelist>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
<title>Notes</title>
|
||||
|
||||
<para>
|
||||
The recommended syntax for referencing an ordered-set aggregate
|
||||
is to write <literal>ORDER BY</> between the direct and aggregated
|
||||
argument specifications, in the same style as in
|
||||
<xref linkend="sql-createaggregate">. However, it will also work to
|
||||
omit <literal>ORDER BY</> and just run the direct and aggregated
|
||||
argument specifications into a single list. In this abbreviated form,
|
||||
if <literal>VARIADIC "any"</> was used in both the direct and
|
||||
aggregated argument lists, write <literal>VARIADIC "any"</> only once.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
<title>Examples</title>
|
||||
|
||||
@@ -148,11 +169,17 @@ ALTER AGGREGATE myavg(integer) OWNER TO joe;
|
||||
</para>
|
||||
|
||||
<para>
|
||||
To move the aggregate function <literal>myavg</literal> for type
|
||||
<type>integer</type> into schema <literal>myschema</literal>:
|
||||
To move the ordered-set aggregate <literal>mypercentile</literal> with
|
||||
direct argument of type <type>float8</type> and aggregated argument
|
||||
of type <type>integer</type> into schema <literal>myschema</literal>:
|
||||
<programlisting>
|
||||
ALTER AGGREGATE myavg(integer) SET SCHEMA myschema;
|
||||
</programlisting></para>
|
||||
ALTER AGGREGATE mypercentile(float8 ORDER BY integer) SET SCHEMA myschema;
|
||||
</programlisting>
|
||||
This will work too:
|
||||
<programlisting>
|
||||
ALTER AGGREGATE mypercentile(float8, integer) SET SCHEMA myschema;
|
||||
</programlisting>
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -23,7 +23,7 @@ PostgreSQL documentation
|
||||
<synopsis>
|
||||
COMMENT ON
|
||||
{
|
||||
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> |
|
||||
COLUMN <replaceable class="PARAMETER">relation_name</replaceable>.<replaceable class="PARAMETER">column_name</replaceable> |
|
||||
@@ -58,6 +58,12 @@ COMMENT ON
|
||||
TYPE <replaceable class="PARAMETER">object_name</replaceable> |
|
||||
VIEW <replaceable class="PARAMETER">object_name</replaceable>
|
||||
} IS '<replaceable class="PARAMETER">text</replaceable>'
|
||||
|
||||
<phrase>where <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>
|
||||
|
||||
@@ -101,7 +107,7 @@ COMMENT ON
|
||||
<varlistentry>
|
||||
<term><replaceable class="parameter">object_name</replaceable></term>
|
||||
<term><replaceable class="parameter">relation_name</replaceable>.<replaceable>column_name</replaceable></term>
|
||||
<term><replaceable class="parameter">agg_name</replaceable></term>
|
||||
<term><replaceable class="parameter">aggregate_name</replaceable></term>
|
||||
<term><replaceable class="parameter">constraint_name</replaceable></term>
|
||||
<term><replaceable class="parameter">function_name</replaceable></term>
|
||||
<term><replaceable class="parameter">operator_name</replaceable></term>
|
||||
@@ -120,17 +126,6 @@ COMMENT ON
|
||||
</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>
|
||||
@@ -153,7 +148,8 @@ COMMENT ON
|
||||
<term><replaceable class="parameter">argmode</replaceable></term>
|
||||
<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>COMMENT</command> does not actually pay
|
||||
@@ -169,7 +165,7 @@ COMMENT ON
|
||||
<term><replaceable class="parameter">argname</replaceable></term>
|
||||
<listitem>
|
||||
<para>
|
||||
The name of a function argument.
|
||||
The name of a function or aggregate argument.
|
||||
Note that <command>COMMENT</command> does not actually pay
|
||||
any attention to argument names, since only the argument data
|
||||
types are needed to determine the function's identity.
|
||||
@@ -181,8 +177,7 @@ COMMENT ON
|
||||
<term><replaceable class="parameter">argtype</replaceable></term>
|
||||
<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>
|
||||
|
||||
@@ -21,7 +21,7 @@ PostgreSQL documentation
|
||||
|
||||
<refsynopsisdiv>
|
||||
<synopsis>
|
||||
CREATE AGGREGATE <replaceable class="parameter">name</replaceable> ( [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">arg_name</replaceable> ] <replaceable class="parameter">arg_data_type</replaceable> [ , ... ] ) (
|
||||
CREATE AGGREGATE <replaceable class="parameter">name</replaceable> ( [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">arg_data_type</replaceable> [ , ... ] ) (
|
||||
SFUNC = <replaceable class="PARAMETER">sfunc</replaceable>,
|
||||
STYPE = <replaceable class="PARAMETER">state_data_type</replaceable>
|
||||
[ , SSPACE = <replaceable class="PARAMETER">state_data_size</replaceable> ]
|
||||
@@ -30,6 +30,16 @@ CREATE AGGREGATE <replaceable class="parameter">name</replaceable> ( [ <replacea
|
||||
[ , SORTOP = <replaceable class="PARAMETER">sort_operator</replaceable> ]
|
||||
)
|
||||
|
||||
CREATE AGGREGATE <replaceable class="parameter">name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">arg_data_type</replaceable> [ , ... ] ]
|
||||
ORDER BY [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">arg_data_type</replaceable> [ , ... ] ) (
|
||||
SFUNC = <replaceable class="PARAMETER">sfunc</replaceable>,
|
||||
STYPE = <replaceable class="PARAMETER">state_data_type</replaceable>
|
||||
[ , SSPACE = <replaceable class="PARAMETER">state_data_size</replaceable> ]
|
||||
[ , FINALFUNC = <replaceable class="PARAMETER">ffunc</replaceable> ]
|
||||
[ , INITCOND = <replaceable class="PARAMETER">initial_condition</replaceable> ]
|
||||
[ , HYPOTHETICAL ]
|
||||
)
|
||||
|
||||
<phrase>or the old syntax</phrase>
|
||||
|
||||
CREATE AGGREGATE <replaceable class="PARAMETER">name</replaceable> (
|
||||
@@ -69,6 +79,8 @@ CREATE AGGREGATE <replaceable class="PARAMETER">name</replaceable> (
|
||||
name and input data type(s) of an aggregate must also be distinct from
|
||||
the name and input data type(s) of every ordinary function in the same
|
||||
schema.
|
||||
This behavior is identical to overloading of ordinary function names
|
||||
(see <xref linkend="sql-createfunction">).
|
||||
</para>
|
||||
|
||||
<para>
|
||||
@@ -128,7 +140,7 @@ CREATE AGGREGATE <replaceable class="PARAMETER">name</replaceable> (
|
||||
<para>
|
||||
If the state transition function is not strict, then it will be called
|
||||
unconditionally at each input row, and must deal with null inputs
|
||||
and null transition values for itself. This allows the aggregate
|
||||
and null state values for itself. This allows the aggregate
|
||||
author to have full control over the aggregate's handling of null values.
|
||||
</para>
|
||||
|
||||
@@ -142,6 +154,22 @@ CREATE AGGREGATE <replaceable class="PARAMETER">name</replaceable> (
|
||||
input rows.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The syntax with <literal>ORDER BY</literal> in the parameter list creates
|
||||
a special type of aggregate called an <firstterm>ordered-set
|
||||
aggregate</firstterm>; or if <literal>HYPOTHETICAL</> is specified, then
|
||||
a <firstterm>hypothetical-set aggregate</firstterm> is created. These
|
||||
aggregates operate over groups of sorted values in order-dependent ways,
|
||||
so that specification of an input sort order is an essential part of a
|
||||
call. Also, they can have <firstterm>direct</> arguments, which are
|
||||
arguments that are evaluated only once per aggregation rather than once
|
||||
per input row. Hypothetical-set aggregates are a subclass of ordered-set
|
||||
aggregates in which some of the direct arguments are required to match,
|
||||
in number and datatypes, the aggregated argument columns. This allows
|
||||
the values of those direct arguments to be added to the collection of
|
||||
aggregate-input rows as an additional <quote>hypothetical</> row.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Aggregates that behave like <function>MIN</> or <function>MAX</> can
|
||||
sometimes be optimized by looking into an index instead of scanning every
|
||||
@@ -202,7 +230,7 @@ SELECT col FROM tab ORDER BY col USING sortop LIMIT 1;
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><replaceable class="parameter">arg_name</replaceable></term>
|
||||
<term><replaceable class="parameter">argname</replaceable></term>
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
@@ -234,6 +262,7 @@ SELECT col FROM tab ORDER BY col USING sortop LIMIT 1;
|
||||
only one input parameter. To define a zero-argument aggregate function
|
||||
with this syntax, specify the <literal>basetype</> as
|
||||
<literal>"ANY"</> (not <literal>*</>).
|
||||
Ordered-set aggregates cannot be defined with the old syntax.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@@ -243,7 +272,7 @@ SELECT col FROM tab ORDER BY col USING sortop LIMIT 1;
|
||||
<listitem>
|
||||
<para>
|
||||
The name of the state transition function to be called for each
|
||||
input row. For an <replaceable class="PARAMETER">N</>-argument
|
||||
input row. For a normal <replaceable class="PARAMETER">N</>-argument
|
||||
aggregate function, the <replaceable class="PARAMETER">sfunc</>
|
||||
must take <replaceable class="PARAMETER">N</>+1 arguments,
|
||||
the first being of type <replaceable
|
||||
@@ -254,6 +283,13 @@ SELECT col FROM tab ORDER BY col USING sortop LIMIT 1;
|
||||
takes the current state value and the current input data value(s),
|
||||
and returns the next state value.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
For ordered-set (including hypothetical-set) aggregates, the state
|
||||
transition function receives only the current state value and the
|
||||
aggregated arguments, not the direct arguments. Otherwise it is the
|
||||
same.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
@@ -287,7 +323,8 @@ SELECT col FROM tab ORDER BY col USING sortop LIMIT 1;
|
||||
<listitem>
|
||||
<para>
|
||||
The name of the final function called to compute the aggregate's
|
||||
result after all input rows have been traversed. The function
|
||||
result after all input rows have been traversed.
|
||||
For a normal aggregate, this function
|
||||
must take a single argument of type <replaceable
|
||||
class="PARAMETER">state_data_type</replaceable>. The return
|
||||
data type of the aggregate is defined as the return type of this
|
||||
@@ -296,6 +333,17 @@ SELECT col FROM tab ORDER BY col USING sortop LIMIT 1;
|
||||
aggregate's result, and the return type is <replaceable
|
||||
class="PARAMETER">state_data_type</replaceable>.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
For ordered-set (including hypothetical-set) aggregates, the
|
||||
final function receives not only the final state value,
|
||||
but also the values of all the direct arguments, followed by
|
||||
null values corresponding to each aggregated argument.
|
||||
(The reason for including the aggregated arguments in the function
|
||||
signature is that this may be necessary to allow correct resolution
|
||||
of the aggregate result type, when a polymorphic aggregate is
|
||||
being defined.)
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
@@ -319,7 +367,22 @@ SELECT col FROM tab ORDER BY col USING sortop LIMIT 1;
|
||||
<function>MAX</>-like aggregate.
|
||||
This is just an operator name (possibly schema-qualified).
|
||||
The operator is assumed to have the same input data types as
|
||||
the aggregate (which must be a single-argument aggregate).
|
||||
the aggregate (which must be a single-argument normal aggregate).
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>HYPOTHETICAL</literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
For ordered-set aggregates only, this flag specifies that the aggregate
|
||||
arguments are to be processed according to the requirements for
|
||||
hypothetical-set aggregates: that is, the last few direct arguments must
|
||||
match the data types of the aggregated (<literal>WITHIN GROUP</>)
|
||||
arguments. The <literal>HYPOTHETICAL</literal> flag has no effect on
|
||||
run-time behavior, only on parse-time resolution of the data types and
|
||||
collations of the aggregate's arguments.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@@ -331,6 +394,29 @@ SELECT col FROM tab ORDER BY col USING sortop LIMIT 1;
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
<title>Notes</title>
|
||||
|
||||
<para>
|
||||
The syntax for ordered-set aggregates allows <literal>VARIADIC</>
|
||||
to be specified for both the last direct parameter and the last
|
||||
aggregated (<literal>WITHIN GROUP</>) parameter. However, the
|
||||
current implementation restricts use of <literal>VARIADIC</>
|
||||
in two ways. First, ordered-set aggregates can only use
|
||||
<literal>VARIADIC "any"</>, not other variadic array types.
|
||||
Second, if the last direct parameter is <literal>VARIADIC "any"</>,
|
||||
then there can be only one aggregated parameter and it must also
|
||||
be <literal>VARIADIC "any"</>. (In the representation used in the
|
||||
system catalogs, these two parameters are merged into a single
|
||||
<literal>VARIADIC "any"</> item, since <structname>pg_proc</> cannot
|
||||
represent functions with more than one <literal>VARIADIC</> parameter.)
|
||||
If the aggregate is a hypothetical-set aggregate, the direct arguments
|
||||
that match the <literal>VARIADIC "any"</> parameter are the hypothetical
|
||||
ones; any preceding parameters represent additional direct arguments
|
||||
that are not constrained to match the aggregated arguments.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
<title>Examples</title>
|
||||
|
||||
|
||||
@@ -21,9 +21,13 @@ PostgreSQL documentation
|
||||
|
||||
<refsynopsisdiv>
|
||||
<synopsis>
|
||||
DROP AGGREGATE [ IF EXISTS ]
|
||||
<replaceable class="parameter">name</replaceable> ( [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">arg_name</replaceable> ] <replaceable class="parameter">arg_data_type</replaceable> [ , ... ] )
|
||||
[ CASCADE | RESTRICT ]
|
||||
DROP AGGREGATE [ IF EXISTS ] <replaceable>name</replaceable> ( <replaceable>aggregate_signature</replaceable> ) [ CASCADE | RESTRICT ]
|
||||
|
||||
<phrase>where <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>
|
||||
|
||||
@@ -73,7 +77,7 @@ DROP AGGREGATE [ IF EXISTS ]
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><replaceable class="parameter">arg_name</replaceable></term>
|
||||
<term><replaceable class="parameter">argname</replaceable></term>
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
@@ -86,12 +90,15 @@ DROP AGGREGATE [ IF EXISTS ]
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><replaceable class="parameter">arg_data_type</replaceable></term>
|
||||
<term><replaceable class="parameter">argtype</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.
|
||||
To reference an ordered-set aggregate function, write
|
||||
<literal>ORDER BY</> between the direct and aggregated argument
|
||||
specifications.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@@ -117,6 +124,15 @@ DROP AGGREGATE [ IF EXISTS ]
|
||||
</variablelist>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
<title>Notes</title>
|
||||
|
||||
<para>
|
||||
Alternative syntaxes for referencing ordered-set aggregates
|
||||
are described under <xref linkend="sql-alteraggregate">.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
<title>Examples</title>
|
||||
|
||||
@@ -125,7 +141,17 @@ DROP AGGREGATE [ IF EXISTS ]
|
||||
<type>integer</type>:
|
||||
<programlisting>
|
||||
DROP AGGREGATE myavg(integer);
|
||||
</programlisting></para>
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
To remove the hypothetical-set aggregate function <literal>myrank</>,
|
||||
which takes an arbitrary list of ordering columns and a matching list
|
||||
of direct arguments:
|
||||
<programlisting>
|
||||
DROP AGGREGATE myrank(VARIADIC "any" ORDER BY VARIADIC "any");
|
||||
</programlisting>
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
|
||||
@@ -25,7 +25,7 @@ SECURITY LABEL [ FOR <replaceable class="PARAMETER">provider</replaceable> ] ON
|
||||
{
|
||||
TABLE <replaceable class="PARAMETER">object_name</replaceable> |
|
||||
COLUMN <replaceable class="PARAMETER">table_name</replaceable>.<replaceable class="PARAMETER">column_name</replaceable> |
|
||||
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> ) |
|
||||
DATABASE <replaceable class="PARAMETER">object_name</replaceable> |
|
||||
DOMAIN <replaceable class="PARAMETER">object_name</replaceable> |
|
||||
EVENT TRIGGER <replaceable class="PARAMETER">object_name</replaceable> |
|
||||
@@ -41,6 +41,12 @@ SECURITY LABEL [ FOR <replaceable class="PARAMETER">provider</replaceable> ] ON
|
||||
TYPE <replaceable class="PARAMETER">object_name</replaceable> |
|
||||
VIEW <replaceable class="PARAMETER">object_name</replaceable>
|
||||
} IS '<replaceable class="PARAMETER">label</replaceable>'
|
||||
|
||||
<phrase>where <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>
|
||||
|
||||
@@ -83,7 +89,7 @@ SECURITY LABEL [ FOR <replaceable class="PARAMETER">provider</replaceable> ] ON
|
||||
<varlistentry>
|
||||
<term><replaceable class="parameter">object_name</replaceable></term>
|
||||
<term><replaceable class="parameter">table_name.column_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>
|
||||
<listitem>
|
||||
<para>
|
||||
@@ -106,23 +112,13 @@ SECURITY LABEL [ FOR <replaceable class="PARAMETER">provider</replaceable> ] ON
|
||||
</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 class="parameter">argmode</replaceable></term>
|
||||
|
||||
<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>SECURITY LABEL</command> does not actually
|
||||
@@ -139,7 +135,7 @@ SECURITY LABEL [ FOR <replaceable class="PARAMETER">provider</replaceable> ] ON
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
The name of a function argument.
|
||||
The name of a function or aggregate argument.
|
||||
Note that <command>SECURITY LABEL</command> does not actually
|
||||
pay any attention to argument names, since only the argument data
|
||||
types are needed to determine the function's identity.
|
||||
@@ -152,8 +148,7 @@ SECURITY LABEL [ FOR <replaceable class="PARAMETER">provider</replaceable> ] ON
|
||||
|
||||
<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