Select NULL Values in SQLAlchemy

前端 未结 3 1707
遥遥无期
遥遥无期 2020-12-05 16:54

Here\'s my (PostgreSQL) table --

test=> create table people (name varchar primary key,
                            marriage_status varchar) ; 

test=>          


        
3条回答
  •  醉梦人生
    2020-12-05 17:24

    Since SQLAlchemy 0.7.9 you may use the is_ method of the column.

    A filter expression like:

    filter(or_(people.marriage_status!='married', people.marriage_status.is_(None)))

    will generate the parameterized SQL:

    WHERE people.marriage_status != %(status_1)s OR people.marriage_status IS NULL

提交回复
热议问题