开发者

how to pass a not like operator in a sqlalchemy ORM query

开发者 https://www.devze.com 2023-02-11 08:38 出处:网络
I\'ve got a q开发者_运维问答uery: MyModel.query.filter(Mymodel.name.contains(\'a_string\')) I need to do the same query but with the negation (a not like operator) but didn\'t find any operator mat

I've got a q开发者_运维问答uery:

MyModel.query.filter(Mymodel.name.contains('a_string'))

I need to do the same query but with the negation (a not like operator) but didn't find any operator matching my need in the SQLAlchemy documentation.

Is there any way to do it without using the sql part of SQLAlchemy???


Just negate the filter:

MyModel.query.filter(sqlalchemy.not_(Mymodel.name.contains('a_string')))


There is now a notlike() method. Couldn't find it in the docs but it exists!

MyModel.query.filter(Mymodel.name.notlike('%a_string%'))
0

精彩评论

暂无评论...
验证码 换一张
取 消