date types incoherent per DP-API 2.0?

Brandon Craig Rhodes <brandon.rhodes-r3/[email protected]> Tue, 24 Aug 2004 11:03:54 -0400
Newsgroups gmane.comp.python.db.pypgsql.user
Message-ID <[email protected]>
The Python DB-API 2.0 describes the following function and type:

        Date(year,month,day)
            This function constructs an object holding a date value.

        DATETIME
            This type object is used to describe date/time columns in
            a database.

If one naively assumes that the Date(...) function will return
instances of the type DATETIME, then one will be disappointed by
psycopg - the function yields values of <type 'datetime'> instead.

More surprising is that psycopg actually seems to violate the standard
by not using not using the type DATETIME when returning timestamps
from database tables; selecting a value of SQL type TIMESTAMP from a
table returns a full-fledged DateTime object:

>>> d
<DateTime object for '2003-12-17 00:00:00.00' at 401dce58>
>>> type(d)
<type 'DateTime'>

where 'DateTime' comes from the mx.DateTime module.  In order to make
psycopg consistent, I suggest:

   - That psycopg.DATETIME, rather than being an apparently unused
     type, become a reference to the mx.DateTime.DateTime type that
     psycopg is actually using to return dates.  I believe that this
     change is necessary to bring this aspect of psycopg into
     conformance with the DB-API.

   - That the psycopg.Date(...) and other time construction functions
     return DateTime instances so they can be most easily compared
     with dates and times returned by queries.

I am perfectly willing to jump over to the devel list and do this
coding myself; but I wanted to ask here first in case I'm
misunderstanding something.

Thanks,
-- 
Brandon Craig Rhodes                         http://www.rhodesmill.org/brandon
Georgia Tech                                            brandon-r3/[email protected]



-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285