|
From: Timothy S. <ti...@op...> - 2004-11-18 04:54:37
|
Billy G. Allie wrote:
> -----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....: Bil...@mu...
> | /| | 7436 Hartwell | MSN.......: B_G...@em...
> |-/-|----- | 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
> _______________________________________________
> Pypgsql-users mailing list
> Pyp...@li...
> https://lists.sourceforge.net/lists/listinfo/pypgsql-users
>
>
so i have float types ( becuase for various reasons thats what i'm
forced to use) how do i pass them in? i understand the first part of
what you are saying, if i pass string data in it will put it in
correctly for any database type.
|