sqlalchemy-utc
sqlalchemy-utc copied to clipboard
PostgreSQL utc_now() needs to have specific UTC timezone
default_sql_now returns CURRENT_TIMESTAMP for psql, but without specifying UTC this returns the server's local time.
SQLAlchemy docs recommend the following implementation for a psql utc_now():
@compiles(utcnow, 'postgresql')
def pg_utcnow(element, compiler, **kw):
return "TIMEZONE('utc', CURRENT_TIMESTAMP)"