Здесь моя таблица (PostgreSQL) -
test=> create table people (name varchar primary key,
marriage_status varchar) ;
test=> insert into people values ('Ken', 'married');
test=> insert into people values ('May', 'single');
test=> insert into people values ('Joe', NULL);
Я хочу выбрать всех людей, которые не известны как состоящие в браке, т.е. в том числе с NULL marriage_status.
Это работает не -
test=> select * from people where marriage_status != 'married' ;
name | marriage_status
------+-----------------
May | single
(1 row)
Конечно, это делает -
test=> select * from people where marriage_status != 'married'
or marriage_status is NULL ;
name | marriage_status
------+-----------------
May | single
Joe |
Проблема в том, что я обращаюсь к нему из SQLAlchemy с помощью
...filter(or_(people.marriage_status!='married',
people.marriage_status is None))
который переводится на
SELECT people.name as name,
people.marriage_status as marriage_status
FROM people
WHERE people.marriage_status != %(status_1)s OR False
sqlalchemy.engine.base.Engine.... {'status_1': 'married'}
И работает не -
test=> select * from people where marriage_status != 'married'
or False;
name | marriage_status
------+-----------------
May | single
(1 row)
не делает -
test=> select * from people where marriage_status != 'married'
or NULL;
name | marriage_status
------+-----------------
May | single
(1 row)
Как выбрать значения NULL через SQLAlchemy?