Re: Python interface and Money?

From: darcy(at)druid(dot)net (D'Arcy J(dot)M(dot) Cain)
To: jmcgraw(at)databill(dot)com (Joel Mc Graw)
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: Python interface and Money?
Date: 2001-10-24 12:04:44
Message-ID: 20011024120444.32D2B1A65@druid.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

Thus spake Joel Mc Graw
> I have a table that has a column of type money. A query such as "select
> sum(document_amount) from foo" returns the correct result when executed
> from psql, yet the same query returns the wrong answer (it appears to be
> a rounding issue--something like "1234.9999999999...") when executed
> through PygreSQL. Is there a workaround or a fix?

That sounds like a Python issue. The correct value is passed to the
Python function as a string since it is always stored and delivered
correctly in the database. That's sort of the point of the money type.

I have been thinking of creating a money type in Python so that this
won't happen but haven't got around to it yet. In the meantime you
can always format it with "%.2f" to get the correct value displayed.

> While browsing the mailing list for an answer to this problem I found
> several references to the money type being deprecated. Is that the
> problem?

They keep saying that DECIMAL should be used instead but they are not
exactly equivalent. The MONEY type was originally written with locale
support and displays the local currency symbol.

--
D'Arcy J.M. Cain <darcy(at){druid|vex}.net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Thomas Lockhart 2001-10-24 13:44:35 Re: Python interface and Money?
Previous Message Christof Petig 2001-10-24 11:27:48 ECPG: Automatic Storage allocation for NULL-pointing output variables