NOT IN
All functions > COMPARISON > NOT IN
Returns TRUE if a value does NOT exist in a list of values.
Syntax
expr NOT IN (value, value, ...)
Notes
- Value and list elements must be of compatible types
- Returns TRUE if the value does not match any element in the list
- Returns FALSE if the value is found in the list
- NULL handling: if value is NULL, returns NULL; if any list element is NULL and value doesn't match other elements, returns NULL
- Equivalent to chaining
!=with AND across the list - Opposite of IN
Related Functions
Examples
Numeric values
FeatureQL
SELECT
f1 := 6 NOT IN (1, 2, 3, 4, 5), -- Number not in list
f2 := 5 NOT IN (1, 2, 3, 4, 5), -- Number in list
f3 := NULL::BIGINT NOT IN (1, 2, 3) -- NULL value
;Result
| f1 BOOLEAN | f2 BOOLEAN | f3 BOOLEAN |
|---|---|---|
| true | false | NULL |
String values
FeatureQL
SELECT
f1 := 'grape' NOT IN ('apple', 'banana', 'cherry'), -- String not in list
f2 := 'apple' NOT IN ('apple', 'banana', 'cherry'), -- String in list
f3 := NULL::VARCHAR NOT IN ('a', 'b', 'c') -- NULL string
;Result
| f1 BOOLEAN | f2 BOOLEAN | f3 BOOLEAN |
|---|---|---|
| true | false | NULL |
Other types
FeatureQL
SELECT
f1 := FALSE NOT IN (TRUE), -- Boolean not in list
f2 := DATE '2024-06-15' NOT IN (DATE '2024-01-01', DATE '2024-12-31') -- Date not in list
;Result
| f1 BOOLEAN | f2 BOOLEAN |
|---|---|
| true | true |