Skip site navigation (1) Skip section navigation (2)

Re: Python interface and Money?

From: Hannu Krosing <hannu(at)tm(dot)ee>
To: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>
Cc: Joel Mc Graw <jmcgraw(at)databill(dot)com>, pgsql-interfaces(at)postgresql(dot)org
Subject: Re: Python interface and Money?
Date: 2001-10-24 17:09:08
Message-ID: 3BD6F5B4.40767418@tm.ee (view raw or flat)
Thread:
Lists: pgsql-interfaces
"D'Arcy J.M. Cain" wrote:
> 
> 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.

There are pure python BigDecimal and Money types available in the same 
place as m2crypto:

http://www.post1.com/home/ngps/m2/ 

Last time I checked the license seemed to be compatible.

> > 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.

This of course will be a real PITA to parse reliably in the adapter ;(

--------------
Hannu

In response to

pgsql-interfaces by date

Next:From: Tom LaneDate: 2001-10-24 21:10:44
Subject: Re: Python interface and Money?
Previous:From: nitinpdhavaleDate: 2001-10-24 15:13:10
Subject: variable length arrays (fields)

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group