By using the PostgreSQL Python module psycopg2, I want to find rows that have an end time that falls before some timestamp. I tried to do this with a cursor.execute(…)
on a SQL query with … where end_time < %s
, where %s replaced by a datetime.datetime
object with a timezone. The SQL generated by psycopg2 is:
select * from my_table where end_time < '2014-05-01T13:00:00+00:00'::timestamptz;
which returns a row like:
id | start_time | end_time
331 | 2014-05-01 14:55:00 | 2014-05-01 15:05:00
The end time is not earlier than 2014-05-01 at 13:00 UTC, contrary to what I was expecting.
What is the proper way of performing the desired time selection in psycopg2?