以下错误的最可能原因是什么,我该如何解决?我不明白为什么 SQLAlchemy 会生成一个缺少表达式的查询!该代码适用于 SQLite,但在 Oracle 上失败。下面的 SQL 查询有什么问题?
此 Python 代码适用于 SQLite,但在 Oracle 11g 上失败:
q = (session.query(locomotion_class).join(LocomotionLink, LocomotionLink.parent_id == self.id).filter(LocomotionLink.child_id == locomotion_class.id, LocomotionLink.child_id != self.id))
# locomotion_class is any of the subclasses of Locomotion (in this case Virion)
return session.query(q.exists()).scalar()
以上结果导致以下查询:
SELECT EXISTS (
SELECT 1
FROM locomotion
JOIN virion ON locomotion.id = virion.id
JOIN locomotion_link ON locomotion_link.parent_id = 16
WHERE locomotion_link.child_id = virion.id AND locomotion_link.child_id != 16
) AS anon_1 FROM DUAL
它适用于 SQLite,但在 Oracle 11g 上失败
"Internal Server Error: (cx.Oracle.DatabaseError) ORA-00936: missing expression"
当我尝试在 sqlplus 中运行生成的表达式时,它在“parent_id = 16”中显示星号低于 6(即直接在 WHERE 之前),但我看不到有任何遗漏。