Skip site navigation (1) Skip section navigation (2)

Change in datetime type casting

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: psycopg(at)postgresql(dot)org
Subject: Change in datetime type casting
Date: 2012-06-27 23:19:34
Message-ID: 4FEB9506.5000303@gmail.com (view raw or flat)
Thread:
Lists: psycopg
 From the docs:
 >>> dt = datetime.datetime.now()
 >>> dt
datetime.datetime(2010, 2, 8, 1, 40, 27, 425337)

 >>> cur.mogrify("SELECT %s, %s, %s;", (dt, dt.date(), dt.time()))
"SELECT '2010-02-08T01:40:27.425337', '2010-02-08', '01:40:27.425337';"

Current (2.4.3) behavior:
  dt
Out[28]: datetime.datetime(2012, 6, 27, 16, 11, 33, 125585)

cur1.mogrify("SELECT %s, %s, %s;", (dt, dt.date(), dt.time()))
Out[30]: "SELECT '2012-06-27T16:11:33.125585'::timestamp, 
'2012-06-27'::date, '16:11:33.125585'::time;"

Note the addition of the casts. This is causing problems when using the 
hstore adapter as hstore expects a plain string. Is there a way to get 
around this?

-- 
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com


Responses

psycopg by date

Next:From: Federico Di GregorioDate: 2012-06-28 06:30:58
Subject: Re: Change in datetime type casting
Previous:From: Federico Di GregorioDate: 2012-06-20 13:17:46
Subject: Re: Patches to add support for tox and Travis CI tools to psycopg2

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group