[DB-SIG] How to use DATETIME objects (and other Type Objects)?

Marc Colosimo mcolosimo at mitre.org
Fri Feb 13 10:19:45 EST 2004

On Feb 12, 2004, at 10:32 AM, Marc Colosimo wrote:

> Now that I understand how to use the executeXXX(), I would like to 
> know how to pass in specific type objects to executeXXX() and how to 
> receive them back from fetchXXX().
> For example, if I have a table with a DATETIME format how can I send 
> it in the correct format to executeXXX()? Or if my table has numberic 
> column, how do I use NUMBER Type object to specify this?
  Okay, it must be a slow brain week for me. After looking at some 
driver code I see that I completely missed the point about what NUMBER, 
DATETIME, etc are used for.

My basic question was if I had a real or numeric field in my database, 
how do I tell the driver that it needs to send that. The answer is as 
before, let the drive handle that:

import pgdb

cursor.execute("INSERT INTO mytable (my_id, my_real, my_date) VALUES 
(%s, %s, %s)",
                             (2, 10.2, "now"))

cursor.execute("SELECT my_real, my_date) FROM mytable WHERE my_id = 2")

fetchedL = cursor.fetchone()

print fetchedL

prints this
[10.199999999999999, '2004-02-13 10:05:57.343744']


print fetchedL[0]




if type(clist[0]) == pgdb.FLOAT:
     print "First argument is a pgdb FLOAT"

if type(clist[1]) == float:
     print "First argument is a python float"

Only print's that this is a python float.

When would one use something like pgdb.FLOAT?


More information about the DB-SIG mailing list