我试图将以下查询转换为sqlalchemy:
SELECT
addr_idn,
(SELECT MAX(LastUpdateDate)
FROM (VALUES (crt_dt),(upd_dt)) AS UpdateDate(LastUpdateDate))
AS LastUpdateDate
FROM (
select a. addr_idn,a.crt_dt crt_dt , b.upd_dt upd_dt
from emp_addr
where emp_addr.addr_idn = 1
) a
但是我无法将其转换为sqlalchemy。请帮我转换此查询。
答案 0 :(得分:1)
致谢:Mike Bayer
这里最难的部分是“ FROM VALUES”,它不是内置的 SQLAlchemy。
There is a recipe at
https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/PGValues
that will show how to build a "values()" function that will give you
the VALUES() expression you're looking for.
- SQLAlchemy- Python SQL工具包和对象关系映射器
要发布示例代码,请提供MCVE:最小,完整和 可验证的示例。有关完整信息,请参见http://stackoverflow.com/help/mcve 说明。