Let me keep it simple , Is there a mysql function unix_timestamp(datetime) in SQLAlchemy ? or is there any workaround ?
1 Answer
SQLAlchemy has support for arbitrary SQL functions. See http://www.sqlalchemy.org/docs/core/tutorial.html#functions.
from sqlalchemy.sql import func
for row in conn.execute(select([func.unix_timestamp("a_datetime_column")], ...)):
# ...
3 Comments
skoovill
can it be used for other database engines ?
codeape
No.
func.NNN is a reference to a SQL function with name NNN, The db engine must support NNN. Certain function names are known by SQLAlchemy and are given special treatment, see sqlalchemy.org/docs/core/tutorial.html#functions and sqlalchemy.org/docs/core/…