sqlalchemy-utc icon indicating copy to clipboard operation
sqlalchemy-utc copied to clipboard

PostgreSQL utc_now() needs to have specific UTC timezone

Open yesthesoup opened this issue 5 years ago • 0 comments

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

yesthesoup avatar Mar 16 '20 22:03 yesthesoup