From: Norbert Meissner <norbert.meissner@str.daimler-benz.com>
To: Karel Zak <zakkr@zf.jcu.cz>
Cc: Norbert Meissner <norbert.meissner@str.daimler-benz.com>
Cc: pgsql-admin@postgresql.org <pgsql-admin@postgreSQL.org>
Subject: Re: Bug or Feature ?
Date: Fri, 26 May 2000 20:00:51 +0200
Message-ID: <392EBBD3.6F22423D@syssun11f.rrz.debis.str.daimler-benz.com> (raw)
References: <Pine.LNX.3.96.1000526183525.30646B-100000@ara.zf.jcu.cz>
> > Hi all,
> >
> > i found a strange behaviour in Postgresql 7.0 on FreeBSD 4.0
> >
> > $ createdb foo
> > $psql foo
> > foo=# create table number (a_number int);
> > foo=# insert into number values(1500000000);
> > foo=# insert into number values(1600000000);
> > select avg(a_number) from number;
> > avg
> > ------------
> > -597483648
> >
>
> test=# select avg(a_number::int8) from number;
> avg
> ------------
> 1550000000
> (1 row)
>
> The parser select function from column type. You use 'int' --- the parser
> use avg(int4)....
> Karel
Dear Karel,
thank you for your solution. You can do it this way, but if you have really
big numbers or many rows, you cannot be sure, at which point you have to use
your solution or you have to use it every time, just to be sure.
I was thinking about a solution that doesn't cause an overflow. Please
consider this situation: At the time you will start the query, you will know
how many rows are affected. So you can calculate the average using the formula
row_1 / number_of_rows + row_2 / number_of_rows + ...
you will have to use floats for this calculation and i'm not sure on the
effect of processing time, but you will never get an overflow.
Norbert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: norbert.meissner@str.daimler-benz.com, zakkr@zf.jcu.cz
Subject: Re: Bug or Feature ?
In-Reply-To: <392EBBD3.6F22423D@syssun11f.rrz.debis.str.daimler-benz.com>
References: <Pine.LNX.3.96.1000526183525.30646B-100000@ara.zf.jcu.cz> <392EBBD3.6F22423D@syssun11f.rrz.debis.str.daimler-benz.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox