[英]Operator "NOT LIKE" with peewee
I would need a query where the content "IS NOT LIKE" a value for我需要一个查询,其中内容“不喜欢”的值为
query = (Table
.select()
.where((Table.lastseen < olddate.isoformat()) &
(Table.used==1) &
(Table.ip !% '%/%' ))
.order_by(Table.lastseen.asc())
)
The, doesn't do the trick?的,不做的伎俩? how do i get the LIKE negated?
我如何让 LIKE 被否定?
You have to use ~
instead of !
你必须使用
~
而不是!
. . That is how negation works in
peewee
.这就是
peewee
中否定的工作方式。 You need to wrap the query you wish to negate using parenthesis.您需要使用括号来包装您希望否定的查询。 In your case
(~(Table.ip % '%/%' ))
.在你的情况下
(~(Table.ip % '%/%' ))
。
query = (Table
.select()
.where((Table.lastseen < olddate.isoformat()) &
(Table.used==1) &
(~(Table.ip % '%/%' )))
.order_by(Table.lastseen.asc())
)
Minimum Reproducible Example (Snippet taken from peewee docs)最小可重现示例(摘自 peewee 文档的片段)
from datetime import date
from peewee import *
db = SqliteDatabase('people.db')
class Person(Model):
name = CharField()
birthday = DateField()
class Meta:
database = db # This model uses the "people.db" database.
db.connect()
db.create_tables([Person])
uncle_bob = Person(name='Bob', birthday=date(1960, 1, 15))
uncle_bob.save()
aunt_alice = Person(name='Alice', birthday=date(1965, 1, 15))
aunt_alice.save()
query = Person.select().where(~(Person.name % 'B*')) # not like 'B%', wildcard changes according to database, `*` instead of `%` for SQLite
for i in query:
print(i.name) # Alice
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.