Re: Python interface and Money?

From: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>
To: Joel Mc Graw <jmcgraw(at)databill(dot)com>
Cc: pgsql-interfaces(at)PostgreSQL(dot)org
Subject: Re: Python interface and Money?
Date: 2003-02-26 13:53:18
Message-ID: 200302260853.18997.darcy@druid.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

On Monday 22 October 2001 13:45, Joel Mc Graw wrote:
> 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?

The problem is that Python doesn't (yet) have a native decimal type and so the
closest thing we can convert to is float. There have been attempts at a
decimal type and at some point I will convert to one of them, hopefully the
same one that Python chooses as a standard.

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

There are people who want to remove it but I still think it serves a useful
purpose. I think that it needs to move to a 64 bit int and handle a lot more
type conversions but I moved some stuff to numeric due to the limits and
found a noticeable slowdown when working with lots of aggregates on it. The
int type is just more efficient. I plan on making a contrib version of the
type before it gets deleted if that is what is decided.

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

In response to

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message D'Arcy J.M. Cain 2003-02-26 13:57:07 Re: Python interface and Money?
Previous Message Tom Lane 2003-02-25 21:27:28 Re: debug a mess