psycopg, datetime timestamps and intervals

"Matthew Dennis" <[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
I originally posted this over on the SQLAlchemy list at
http://groups.google.com/group/sqlalchemy/browse_thread/thread/afcce48f204370cfbut
as it seems that it's really a psycopg question/problem, I thought I
would mention it here as well.

When I run:
#!/usr/bin/python


import psycopg2
from datetime import datetime

conn = psycopg2.connect('''dbname=testdb user=postgres host=localhost''')
cur = conn.cursor()

cur.execute("drop table if exists t0")
cur.execute("create table t0(c0 timestamp(0) with time zone)")
cur.execute("insert into t0 values(current_timestamp)")
cur.execute("select c0 from t0 where c0 < %(bindArg)s - interval '1 hour'",
{'bindArg':datetime.utcnow()})

I get:
File "./saerr2.py", line 12, in <module>
    cur.execute("select c0 from t0 where c0 < %(bindArg)s - interval '1
hour'", {'bindArg':datetime.utcnow()})
psycopg2.ProgrammingError: invalid input syntax for type interval:
"2008-04-18T21:30:11.897334"

Running the equivalent in psql gives no problems, perhaps it's only a
problem when using bind variables?

_______________________________________________
Psycopg mailing list
Psycopg-IAPFreCvJWPBWskQ1e/[email protected]
http://lists.initd.org/mailman/listinfo/psycopg
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.