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
Examples
FeatureQL
SELECT
f1 := CONTAINS(ARRAY[1, 2, 3, 4], 3), -- Element exists
f2 := CONTAINS(ARRAY['A', 'B', 'C'], 'B'), -- String element exists
f3 := CONTAINS(ARRAY[1, 2, 3], 5), -- Element does not exist
f4 := CONTAINS(ARRAY['apple', 'banana'], 'cherry'), -- String not found
f5 := CONTAINS(ARRAY[1, 2, 2, 3], 2), -- Duplicate element found
f6 := CONTAINS(ARRAY[1, NULL::BIGINT, 3], NULL::BIGINT), -- NULL element is NULL
f7 := CONTAINS(ARRAY[]::BIGINT[], 1), -- Empty array
f8 := CONTAINS(ARRAY['Hello', 'World'], 'hello') -- Case-sensitive comparison
;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