Re: money types, decimal module

"Billy G. Allie" <[email protected]> Wed, 17 Nov 2004 21:21:40 -0500
Newsgroups gmane.comp.python.db.pypgsql.user
Message-ID <[email protected]>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Timothy Smith wrote:
| Karsten Hilbert wrote:
|
|>> hello i'm stuck with a problem. whats the best way to store money
|>> types.
|>
|> Use numeric.
|>
|> Karsten
|>
|>
| Ok i must be doing something wrong here i'm still getting the same error
| and i have changed my types to numeric.
|
| (EnteredBy,DateEntered,ForDate, ForVenue, TillName,Tape,Cash, GM,
| VenueManager, AsstManager, BarManager, PRCards,   otherPromo, Functions,
| Accounts, Spill, Orings, Variance))
|  File "/usr/local/lib/python2.3/site-packages/pyPgSQL/PgSQL.py", line
| 3048, in execute
|    self.res = self.conn.conn.query(_qstr % parms)
| TypeError: float argument required
|
| here is my code i think is the problem
| cur.execute("INSERT INTO DailyTakings VALUES (%s,%s, %s,
| %s,%s,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f)",
|    (EnteredBy,DateEntered,ForDate, ForVenue, TillName,Tape,Cash, GM,
| VenueManager, AsstManager, BarManager, PRCards,    otherPromo,
| Functions, Accounts, Spill, Orings, Variance))

You need to use '%s' for all the parameters.  If your money values are
defined as money or as numberis(8,2) [actuallay the 9 can be whatever
precision you desire] it will do what you want.  If the values your are
passing in are python numeric typs (e.g. float, etc), you will need to
cast them to the correct (database) type.

For example: Pg_Numeric(cash, 9, 2)

This 'cast' will ensure that the data is sent to the database in the
correct format.

I hope this makes the water less muddy.

- --
____       | Billy G. Allie    | Domain....: [email protected]
|  /|      | 7436 Hartwell     | MSN.......: [email protected]
|-/-|----- | Dearborn, MI 48126|
|/  |LLIE  | (313) 582-1540    |
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFBnAcznmIkMXoVVdURAsaZAKDDmUM43ozJpp5EEJUVTPfxovhATACglsiZ
KTWlGV73EoIUdHoprEz1HDA=
=L6PY
-----END PGP SIGNATURE-----


-------------------------------------------------------
This SF.Net email is sponsored by: InterSystems CACHE
FREE OODBMS DOWNLOAD - A multidimensional database that combines
robust object and relational technologies, making it a perfect match
for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8