CONTAINS()
All functions > ARRAY > CONTAINS()
Returns TRUE if the array contains the specified element.
Signatures
Returns: TRUE if the element exists in the array, FALSE otherwise
CONTAINS(array: ARRAY<T>, element: T) → BOOLEAN sql
| Parameter | Type | Required | Description |
|---|---|---|---|
array | ARRAY<T> | Yes | The array to search in |
element | T | Yes | The element to check for existence |
Notes
- Returns boolean value indicating element presence
- Uses exact match comparison (case-sensitive for strings)
- Returns NULL if checking for NULL element
- Empty arrays always return FALSE
- More efficient than ARRAY_POSITION for simple existence checks
- Supports
ARRAY<ROW>andARRAY<ARRAY<T>>: element and array must share the exact same type; mismatched schemas raise a user error
Aliases
ARRAY_CONTAINS
See also
Examples
FeatureQL
SELECT
-- Element exists
f1 := CONTAINS(ARRAY(1, 2, 3, 4), 3),
-- String element exists
f2 := CONTAINS(ARRAY('A', 'B', 'C'), 'B'),
-- Element does not exist
f3 := CONTAINS(ARRAY(1, 2, 3), 5),
-- String not found
f4 := CONTAINS(ARRAY('apple', 'banana'), 'cherry'),
-- Duplicate element found
f5 := CONTAINS(ARRAY(1, 2, 2, 3), 2),
-- NULL element is NULL
f6 := CONTAINS(ARRAY(1, NULL::BIGINT, 3), NULL::BIGINT),
-- Empty array
f7 := CONTAINS(ARRAY()::BIGINT[], 1),
-- Case-sensitive comparison
f8 := CONTAINS(ARRAY('Hello', 'World'), 'hello')
;Result
| f1 BOOLEAN | f2 BOOLEAN | f3 BOOLEAN | f4 BOOLEAN | f5 BOOLEAN | f6 BOOLEAN | f7 BOOLEAN | f8 BOOLEAN |
|---|---|---|---|---|---|---|---|
| true | true | false | false | true | null | false | false |
On this page