03/18/2023, 12:08 AM
I am using psycopg2 to read a questdb database. I am having trouble with specifying datetimes while filtering. psycopg2 automatically converts timeaware python datetimes to timestamptz types when I read from PG but with questdb, I get the following error
psycopg2.DatabaseError: invalid constant: timestamptz
LINE 1: ... timestamp <= '2023-03-17T19:55:46.342000+00:00'::timestampt...
Do I need to convert my Python datetimes into something else before using them in QuestDB queries? Edit: This is solved now. Seems like QuestDB needs datetimes to be naive and in utc, so what I did before using datetimes to filter rows in psycopg2 is the following (dt is a datetime object with some valid timezone):
dt = dt.astimezone(pytz.timezone("UTC")).replace(tzinfo=None)