How would I amend my calls to
sqlalchemy.func.current_timestamp()
with something that generates
CURRENT_TIMESTAMP AT TIME ZONE 'UTC'
Current time: 16:36:48 UTC. UTC is replaced with Z that is the zero UTC offset. UTC time in ISO-8601 is 16:36:48Z. Note that the Z letter without a space.
PostgreSQL stores the timestamptz in UTC value.
timezone('UTC', now()) turns our current time (of type timestamp with time zone) into the timezonless equivalent in UTC . E.g., SELECT timestamp with time zone '2020-03-16 15:00:00-05' AT TIME ZONE 'UTC' will return 2020-03-16T20:00:00Z .
A quick fix would be to do the following:
func.current_timestamp().op('AT TIME ZONE')('UTC')
A more proper way is to use compiler extension and define custom compilation of CURRENT_TIMESTAMP
. Actually, there's already an example in its docs, which uses a different approach (TIMEZONE
function). Since you only need this for Postgres (I assume from your previous emails in SA mailing list that you're using Postgres), here's another (nicer) quick fix:
func.timezone('UTC', func.current_timestamp())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With