Handling Timezone Column in SQLAlchemy ORM queries #11598
-
|
Whenever I query a column representing a timestamp with timezone data, it returns a UTC datetime. Even when I update the timezone of the session with SET TIMEZONE <>, the output remains in UTC. I have a scenario in my FastAPI application where I need to dynamically change the timezone of the session based on the end user’s location. Of course, using func.timezone(desired_timezone, column) will work, but are there other possible solutions? Also, adding func.timezone() to every single query feels tiresome, as most of the queries in my application involve timezone-aware columns. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
|
The behaviour of "timezone-aware" datetime values depends to some extent on the database being used. What database platform are you using? |
Beta Was this translation helpful? Give feedback.
I tinkered around a bit more, and I found that
does nothing with
postgresql+asyncpg://but seems to work withpostgresql+psycopg://