La documentazione mostra here come utilizzare l'operatore IN
, ma non sono riuscito a trovare come utilizzare l'operatore NOT IN
.Operatore NON IN con Peewee
Se inserisco un not <<
, viene visualizzato un errore di sintassi.
Se inserisco uno not <FieldName> <<
, c'è un WHERE False
invece di un subquery come WHERE (<FieldName> NOT IN (SELECT ...
.
Ecco l'output con gli esempi di documentazione. Il primo è corretto, il secondo e il terzo sono errati.
>>> Tweet.select().where(Tweet.user << a_users).sql()
('SELECT t1."id", t1."user_id", t1."message", t1."created_date", t1."is_published" FROM "tweet" AS t1 WHERE (t1."user_id" IN (SELECT t2."id" FROM "user" AS t2 WHERE (Lower(Substr(t2."username", ?, ?)) = ?)))', [1, 1, 'a'])
>>> Tweet.select().where(not Tweet.user << a_users).sql()
('SELECT t1."id", t1."user_id", t1."message", t1."created_date", t1."is_published" FROM "tweet" AS t1 WHERE ?', [False])
>>> Tweet.select().where(Tweet.user not << a_users).sql()
SyntaxError: invalid syntax
'not in' è letteralmente un singolo operatore denominato' not in', non significa che è possibile inserire 'not' prima di qualsiasi altro operatore. Il fatto che Peewee reinterpreti '<<' per significare un 'IN' SQL non significa che possa cambiare la sintassi di Python. – abarnert
@abarnert Lo so ... quindi la mia domanda – stenci