PostgreSQL documentation specifies 2-element array for float8_accum but 3-element array expected

Started by Disc Magnetabout 15 years ago3 messagesgeneral
Jump to latest
#1Disc Magnet
discmagnet@gmail.com

I was learning how to create my own aggregate functions from
http://www.postgresql.org/docs/9.0/static/xaggr.html

I copied the avg() example as

CREATE TABLE numbers (
value integer
);

insert into numbers values (2);
insert into numbers values (3);
insert into numbers values (4);

CREATE AGGREGATE myavg(float8) (
sfunc = float8_accum,
stype = float8[],
finalfunc = float8_avg,
initcond = '{0,0}'
);

On trying to run this, I get this error:

cdb=# select myavg(value) from numbers;
ERROR: float8_accum: expected 3-element float8 array

How can I fix this?

#2Merlin Moncure
mmoncure@gmail.com
In reply to: Disc Magnet (#1)
Re: PostgreSQL documentation specifies 2-element array for float8_accum but 3-element array expected

On Wed, Mar 23, 2011 at 8:03 AM, Disc Magnet <discmagnet@gmail.com> wrote:

I was learning how to create my own aggregate functions from
http://www.postgresql.org/docs/9.0/static/xaggr.html

I copied the avg() example as

CREATE TABLE numbers (
   value integer
);

insert into numbers values (2);
insert into numbers values (3);
insert into numbers values (4);

CREATE AGGREGATE myavg(float8) (
   sfunc = float8_accum,
   stype = float8[],
   finalfunc = float8_avg,
   initcond = '{0,0}'
);

On trying to run this, I get this error:

cdb=# select myavg(value) from numbers;
ERROR:  float8_accum: expected 3-element float8 array

How can I fix this?

how embarrassing -- the initcont should be: '{0,0,0}' :^).

merlin

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Disc Magnet (#1)
Re: PostgreSQL documentation specifies 2-element array for float8_accum but 3-element array expected

Disc Magnet <discmagnet@gmail.com> writes:

CREATE AGGREGATE myavg(float8) (
sfunc = float8_accum,
stype = float8[],
finalfunc = float8_avg,
initcond = '{0,0}'
);

On trying to run this, I get this error:

cdb=# select myavg(value) from numbers;
ERROR: float8_accum: expected 3-element float8 array

Hm, it looks like that example has been wrong from day one ---
float8_accum has expected a 3-element array for its entire existence.
I thought maybe the code and docs had gotten out of sync later, but
AFAICS this was a thinko in the original commit. Should say
initcond = '{0,0,0}'

regards, tom lane