I'd like to get the difference between two dates working on SQLAlchemy. Using Postgresql I have the following working:
SELECT
EXTRACT(EPOCH FROM ('2019-02-11 17:59:05.953894'::timestamp - '2019-02-11 17:59:01.953894'::timestamp))
However, I have problems when attempting the same in SQLAlchemy:
session.query(func.extract('epoch',func.date(subquery.c.dt_final.cast(Date)))-
func.date(subquery.c.dt_start.cast(Date))).all()
Getting this error:
ProgrammingError: (psycopg2.errors.UndefinedFunction) operator does not exist: double precision - date
LINE 1: ...h FROM date(CAST(anon_2.dt_final AS DATE))) - date(CAS...
^
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
How is the proper way to get the difference between two dates in SQLAlchemy?
Thanks