Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit63fe94d

Browse files
committed
Improve user-defined-aggregates documentation.
On closer inspection, that two-element initcond value seems to have beena little white lie to avoid explaining the full behavior of float8_accum.But if people are going to expect the examples to be exactly correct,I suppose we'd better explain. Per comment from Thom Brown.
1 parent24cdee8 commit63fe94d

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

‎doc/src/sgml/xaggr.sgml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ SELECT sum(a) FROM test_complex;
7070
expects <function>sum</function> to behave that way. We can do this simply by
7171
omitting the <literal>initcond</literal> phrase, so that the initial state
7272
condition is null. Ordinarily this would mean that the <literal>sfunc</literal>
73-
would need to check for a null state-condition input, but for
73+
would need to check for a null state-condition input. But for
7474
<function>sum</function> and some other simple aggregates like
7575
<function>max</> and <function>min</>,
7676
it is sufficient to insert the first nonnull input value into
@@ -95,8 +95,8 @@ SELECT sum(a) FROM test_complex;
9595
It requires
9696
two pieces of running state: the sum of the inputs and the count
9797
of the number of inputs. The final result is obtained by dividing
98-
these quantities. Average is typically implemented by usinga
99-
two-elementarray as the state value. For example,
98+
these quantities. Average is typically implemented by usingan
99+
array as the state value. For example,
100100
the built-in implementation of <function>avg(float8)</function>
101101
looks like:
102102

@@ -106,9 +106,14 @@ CREATE AGGREGATE avg (float8)
106106
sfunc = float8_accum,
107107
stype = float8[],
108108
finalfunc = float8_avg,
109-
initcond = '{0,0,0}'
109+
initcond = '{0,0}'
110110
);
111111
</programlisting>
112+
113+
(<function>float8_accum</> requires a three-element array, not just
114+
two elements, because it accumulates the sum of squares as well as
115+
the sum and count of the inputs. This is so that it can be used for
116+
some other aggregates besides <function>avg</>.)
112117
</para>
113118

114119
<para>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp