python - sqlalchemy 如何在查询的时候排除掉数据库字段为 null的
大家讲道理
大家讲道理 2017-04-17 17:54:46
0
2
357

在用sqlalchemy 查询数据的时候 想把数据中为 null的数据排除掉

session.query(employee).filter_by(brand_id is null)

这样不能用,求解。

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
小葫芦

Method 1

session.query(employee).filter_by(employ.brand_id.isnot(None))

Method 2

from sqlalchemy import not_
session.query(employee).filter_by(not_(employ.brand_id==None))

Reference
http://docs.sqlalchemy.org/en/rel_1_0/core/sqlelement.html

巴扎黑

django orm usage is
session.query(employee).exclude(brand_id__isnull=True)

I don’t know how to use sqlalchemy.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template