spoqa / sqlalchemy-utc

SQLAlchemy type to store aware datetime values
https://pypi.python.org/pypi/SQLAlchemy-Utc
MIT License
101 stars 20 forks source link

PostgreSQL utc_now() needs to have specific UTC timezone #9

Open yesthesoup opened 4 years ago

yesthesoup commented 4 years ago

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)"