pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Stanaway <david@stanaway.net>
To: Sonia Sanchez Diaz <sonny@piaget.dgsca.unam.mx>
Cc: pgsql-admin <pgsql-admin@postgresql.org>
Subject: Re: SUM PROBLEM...
Date: 09 May 2002 11:25:07 -0500
Message-ID: <1020961507.6259.57.camel@ciderbox> (raw)
In-Reply-To: <Pine.SGI.4.10.10205091043130.215963-100000@piaget.dgsca.unam.mx>
References: <Pine.SGI.4.10.10205091043130.215963-100000@piaget.dgsca.unam.mx>

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

Attachments:

  signature.asc (application/pgp-signature, 523B) download

view thread (2+ messages)  latest in thread

Message-ID: <1020961507.6259.57.camel@ciderbox>
Permalink:  ../1020961507.6259.57.camel@ciderbox/
Also on:    postgresql.org/message-id/1020961507.6259.57.camel@ciderbox

 · 

reply

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: david@stanaway.net, sonny@piaget.dgsca.unam.mx
  Subject: Re: SUM PROBLEM...
  In-Reply-To: <1020961507.6259.57.camel@ciderbox>
  References: <Pine.SGI.4.10.10205091043130.215963-100000@piaget.dgsca.unam.mx> <1020961507.6259.57.camel@ciderbox>

* 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