Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 49131476400 for ; Thu, 9 May 2002 12:26:19 -0400 (EDT) Received: from ciderbox.stanaway.net (ciderbox.stanaway.net [170.76.50.98]) by postgresql.org (Postfix) with ESMTP id 46761475EDE for ; Thu, 9 May 2002 12:25:16 -0400 (EDT) Received: by ciderbox.stanaway.net (Postfix, from userid 1000) id 74820935A1; Thu, 9 May 2002 11:25:07 -0500 (CDT) Subject: Re: SUM PROBLEM... From: David Stanaway To: Sonia Sanchez Diaz Cc: pgsql-admin In-Reply-To: References: Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-NebC0xplQfdPussDeW97" X-Mailer: Ximian Evolution 1.0.3 Date: 09 May 2002 11:25:07 -0500 Message-Id: <1020961507.6259.57.camel@ciderbox> Mime-Version: 1.0 X-Archive-Number: 200205/74 X-Sequence-Number: 4249 --=-NebC0xplQfdPussDeW97 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Thu, 2002-05-09 at 12:48, Sonia Sanchez Diaz wrote: >=20 > Hy! >=20 > I have one money type field and I need to plus it, but when I run the > query I get a negative answer! >=20 > But I don't have negative numbers into this field...??? >=20 > What's up here?? >=20 > The query is: >=20 > select sum(field) from table; >=20 > and the answer is: >=20 > 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-DE= CIMAL 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 --=-NebC0xplQfdPussDeW97 Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iQEXAwUAPNqi4r6yIDFGeSAyFALitgP9Ef7GPvYU9DzJJz8fC5pqCs1m+teGckgM 7+b58pVcFc0fXKMVmhty8Ocvp8gI9KB+8QW1pmMmxhszRC/kzq896DZX06bKyXfd E5fJkqbiyh/mYITdMT1Tycpc70b+r5gXBDDZN/4itJ18FyxdhVdYLQKOYELL23up hNUFYLZwOX0D/2L4GWjLnJMOR/KHd6qrny3JZS9Fg3krwRHKpuB3uLo4PcKUyXnO Fbg8YiwOME1X7Smz8kBrs86mZ7UCIzGQwYs3JVy0772yAKoPsiVe37O9wptfq/DN 4Pg8Uvsox9Cdla3cCamBKoii9LlwzabK4ezT1O15+qXdRtis7Gv5srDW =t5d8 -----END PGP SIGNATURE----- --=-NebC0xplQfdPussDeW97--