Money in numeric field

From: Martín Marqués <martin(dot)marques(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Money in numeric field
Date: 2012-04-19 15:40:40
Message-ID: CABeG9LtG=pAV6ttsYiqGYQOqWY=24XDAPtmQ9Z=VGMDXVZb_Eg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have a question involving money data stored in a numeric(9,2) field,
and posible errors with there manipulation.

in short, the table has these columns:

store: int
amount: int2
cost: numeric(9,2)

What I need to find is the total amount of money spent in a particular
store, so I do something like the second query:

SELECT count(*) from material where store = 9;
count
-------
360
(1 fila)

SELECT sum(cost*amount) from material where store = 9;
sum
----------
48244.35
(1 fila)

Is it posible to have errors after multipling the numeric value by and
int and then adding them all with the SUM() function?

If the answer is yes, where do the errors acumulate, and how can I solve it?

P.D.: I'm using PG and PHP in the middle.

--
Martín Marqués
select 'martin.marques' || '@' || 'gmail.com'
DBA, Programador, Administrador

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2012-04-19 15:42:59 Re: Performance degrades until dump/restore
Previous Message Alban Hertroys 2012-04-19 15:40:36 Re: Performance degrades until dump/restore