Re: SUM PROBLEM...

From: David Stanaway <david(at)stanaway(dot)net>
To: Sonia Sanchez Diaz <sonny(at)piaget(dot)dgsca(dot)unam(dot)mx>
Cc: pgsql-admin <pgsql-admin(at)postgresql(dot)org>
Subject: Re: SUM PROBLEM...
Date: 2002-05-09 16:25:07
Message-ID: 1020961507.6259.57.camel@ciderbox
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Thu, 2002-05-09 at 12:48, Sonia Sanchez Diaz wrote:
>
> Hy!
>
> I have one money type field and I need to plus it, but when I run the
> query I get a negative answer!
>
> But I don't have negative numbers into this field...???
>
> What's up here??
>
> The query is:
>
> select sum(field) from table;
>
> and the answer is:
>
> field
> --------
> -$5,083,598.58

Sounds like you are getting an overflow.
http://www.postgresql.org/idocs/index.php?datatype-money.html
Type Name Storage Description Range
money 4 bytes Fixed-precision -21474836.48 to +21474836.47

NB: Its use is deprecated

Try using numeric:
http://www.postgresql.org/idocs/index.php?datatype.html#DATATYPE-NUMERIC-DECIMAL

I am not sure how you can convert the date to numeric, as on my database
(7.2.1) you cannot cast from money to numeric, or float (float would be
a bad idea for storage of monetary data).

select sum(m::numeric) from foo;
ERROR: Cannot cast type 'money' to 'numeric'

Maybe someone else could chime in at this point. : )

--
David Stanaway

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Sonia Sanchez Diaz 2002-05-09 17:48:16 SUM PROBLEM...
Previous Message Bojan Belovic 2002-05-09 15:34:19 Re: db recovery (FATAL 2)