PostgreSQL
 SQL >> Base de données >  >> RDS >> PostgreSQL

Utiliser l'opérateur ANY de PostgreSQL dans une condition NOT IN

Lorsque vous écrivez

select 2 != any(array[2,3,4]); ?column? ---------- t 

2 est comparé à chaque élément du tableau, et s'il est différent de n'importe lequel d'entre eux, le tout s'évalue à true.

Utilisez plutôt not id = any(array[2,3,4]) :

select not 1 = any(array[2,3,4]); ?column? ---------- t select not 2 = any(array[2,3,4]); ?column? ---------- f 

Ou != all :

select 1 != all(array[2,3,4]); ?column? ---------- t select 2 != all(array[2,3,4]); ?column? ---------- f