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
ParameterTypeRequiredDescription
arrayARRAY<T>YesThe array to search in
elementTYesThe 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 BOOLEANf2 BOOLEANf3 BOOLEANf4 BOOLEANf5 BOOLEANf6 BOOLEANf7 BOOLEANf8 BOOLEAN
truetruefalsefalsetruenullfalsefalse

Last update at: 2026/03/03 16:47:38
Last updated: 2026-03-03 16:48:19