Hi,
I've created the following utcnow function as described here:
http://docs.sqlalchemy.org/en/latest/core/compiler.html?highlight=utc#utc-timestamp-function
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql import expression
from sqlalchemy.types import DateTime, String
class utcnow(expression.FunctionElement):
"""A custom SQLAlchemy function that returns the current UTC time"""
type = DateTime()
@compiles(utcnow, 'postgresql')
def pg_utcnow(element, compiler, **kw):
"""Adds a postgres implementation of UTC now function
"""
return "TIMEZONE('utc', CURRENT_TIMESTAMP)"
Whenever I run db.session.execute(utcnow()), I'm getting the exact same
date:
In [12]: db.session.execute(custom_functions.utcnow()).scalar()
Out[12]: datetime.datetime(2018, 3, 28, 18, 28, 49, 879360)
In [13]: db.session.execute(custom_functions.utcnow()).scalar()
Out[13]: datetime.datetime(2018, 3, 28, 18, 28, 49, 879360)
...
I guess its something trivial that I'm doing wrong. any ideas?
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.