Home Explore Blog CI



postgresql

13th chunk of `doc/src/sgml/ref/create_aggregate.sgml`
06643b123f668e0250d9e1dc62c7be219d7e3da45b8a84fb0000000100000c51
 reverse out of the
    running state value.
   </para>

   <para>
    If no moving-aggregate implementation is supplied,
    the aggregate can still be used with moving frames,
    but <productname>PostgreSQL</productname> will recompute the whole
    aggregation whenever the start of the frame moves.
    Note that whether or not the aggregate supports moving-aggregate
    mode, <productname>PostgreSQL</productname> can handle a moving frame
    end without recalculation; this is done by continuing to add new values
    to the aggregate's state.  This is why use of an aggregate as a window
    function requires that the final function be read-only: it must
    not damage the aggregate's state value, so that the aggregation can be
    continued even after an aggregate result value has been obtained for
    one set of frame boundaries.
   </para>

   <para>
    The syntax for ordered-set aggregates allows <literal>VARIADIC</literal>
    to be specified for both the last direct parameter and the last
    aggregated (<literal>WITHIN GROUP</literal>) parameter.  However, the
    current implementation restricts use of <literal>VARIADIC</literal>
    in two ways.  First, ordered-set aggregates can only use
    <literal>VARIADIC "any"</literal>, not other variadic array types.
    Second, if the last direct parameter is <literal>VARIADIC "any"</literal>,
    then there can be only one aggregated parameter and it must also
    be <literal>VARIADIC "any"</literal>.  (In the representation used in the
    system catalogs, these two parameters are merged into a single
    <literal>VARIADIC "any"</literal> item, since <structname>pg_proc</structname> cannot
    represent functions with more than one <literal>VARIADIC</literal> parameter.)
    If the aggregate is a hypothetical-set aggregate, the direct arguments
    that match the <literal>VARIADIC "any"</literal> parameter are the hypothetical
    ones; any preceding parameters represent additional direct arguments
    that are not constrained to match the aggregated arguments.
   </para>

   <para>
    Currently, ordered-set aggregates do not need to support
    moving-aggregate mode, since they cannot be used as window functions.
   </para>

   <para>
    Partial (including parallel) aggregation is currently not supported for
    ordered-set aggregates.  Also, it will never be used for aggregate calls
    that include <literal>DISTINCT</literal> or <literal>ORDER BY</literal> clauses, since
    those semantics cannot be supported during partial aggregation.
  </para>
 </refsect1>

 <refsect1>
  <title>Examples</title>

  <para>
   See <xref linkend="xaggr"/>.
  </para>
 </refsect1>

 <refsect1>
  <title>Compatibility</title>

  <para>
   <command>CREATE AGGREGATE</command> is a
   <productname>PostgreSQL</productname> language extension.  The SQL
   standard does not provide for user-defined aggregate functions.
  </para>
 </refsect1>

 <refsect1>
  <title>See Also</title>

  <simplelist type="inline">
   <member><xref linkend="sql-alteraggregate"/></member>
   <member><xref linkend="sql-dropaggregate"/></member>
  </simplelist>
 </refsect1>
</refentry>

Title: Ordered-Set Aggregates, Restrictions, and Compatibility
Summary
This section covers ordered-set aggregates, noting their syntax for VARIADIC parameters and current implementation restrictions, including only allowing VARIADIC "any". It mentions they do not support moving-aggregate mode or partial aggregation. The section concludes with information on compatibility, stating that CREATE AGGREGATE is a PostgreSQL extension and refers to examples and related commands.