Re: weird sum() results

From: Mark Dalphin <mdalphin(at)amgen(dot)com>
To: pgsql-general(at)hub(dot)org
Subject: Re: weird sum() results
Date: 2000-01-21 02:12:00
Message-ID: 3887C06F.5D661E@amgen.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 19 Jan 2000 16:33:06, Hitesh Patel wrote:

> I have a table with a filed named 'amount' and all the values are
>
> positive values, but if i do this:
>
> select sum(amount) from table where state = 'CA';
>
> I get a negative number. Doing a
>
> select name, amount from table where state = 'CA' and amount < '0';
>
> Returns 0 rows. Any ideas as to why i'm getting a negative value for
> the sum()?
>

If the sum() is larger than the largest possible integer, the values will "wrap around" into the negative
integers. I don't know how many values you are adding, but, assuming you are storing your amount as an
'int4', your sum will wrap at about 2 billion (2,147,483,647).

HTH,
Mark

--
Mark Dalphin email: mdalphin(at)amgen(dot)com
Mail Stop: 29-2-A phone: +1-805-447-4951 (work)
One Amgen Center Drive +1-805-375-0680 (home)
Thousand Oaks, CA 91320 fax: +1-805-499-9955 (work)

Responses

Browse pgsql-general by date

  From Date Subject
Next Message LKembel 2000-01-21 02:46:20 MySQL
Previous Message Bruce Momjian 2000-01-21 02:07:04 Re: [GENERAL] Datatype serial ?