我希望能够在SQLAlchemy上计算两个日期之间的差异。在使用PostgreSQL时,我已经得到了以下的结果:
得到这个错误:
SELECT
EXTRACT(EPOCH FROM ('2019-02-11 17:59:05.953894'::timestamp - '2019-02-11 17:59:01.953894'::timestamp))
然而,当我尝试在SQLAlchemy中做同样的事情时,遇到了问题:
session.query(func.extract('epoch',func.date(subquery.c.dt_final.cast(Date)))-
func.date(subquery.c.dt_start.cast(Date))).all()
得到这个错误:
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.
如何在SQLAlchemy中获取两个日期之间的差异?
谢谢