PostgreSQL Reference Manual - Volume 1 - SQL Language Referenceby The PostgreSQL Global Development Group Paperback (6"x9"), 716 pages ISBN 0954612027 RRP £32.00 ($49.95) Sales of this book support the PostgreSQL project! Get a printed copy>>> |

### 7.17.2 NOT IN

expressionNOT IN (value[, ...])

The right-hand side is a parenthesized list of scalar expressions. The result is “true” if the left-hand expression's result is unequal to all of the right-hand expressions. This is a shorthand notation for

expression<>value1ANDexpression<>value2AND ...

Note that if the left-hand expression yields null, or if there are
no equal right-hand values and at least one right-hand expression yields
null, the result of the `NOT IN`

construct will be null, not true
as one might naively expect.
This is in accordance with SQL's normal rules for Boolean combinations
of null values.

Tip:`x NOT IN y`

is equivalent to`NOT (x IN y)`

in all cases. However, null values are much more likely to trip up the novice when working with`NOT IN`

than when working with`IN`

. It's best to express your condition positively if possible.

ISBN 0954612027 | PostgreSQL Reference Manual - Volume 1 - SQL Language Reference | See the print edition |