CONTAINS_SEQUENCE()

All functions > ARRAY > CONTAINS_SEQUENCE()

Returns TRUE if the array contains the specified sequence as a contiguous subsequence.

Signatures

Returns: TRUE if sequence appears contiguously in array, FALSE otherwise

CONTAINS_SEQUENCE(array: ARRAY<T>, sequence: ARRAY<T>) → BOOLEAN
sql
ParameterTypeRequiredDescription
arrayARRAY<T>YesThe array to search within
sequenceARRAY<T>YesThe contiguous sequence to find

Notes

  • Checks for contiguous subsequence match
  • Elements must appear in order without gaps
  • Returns FALSE if sequence is not found
  • Empty sequence argument yields NULL (not TRUE)
  • Uses element equality comparison

See also

Examples

FeatureQL
SELECT
    f1 := CONTAINS_SEQUENCE(ARRAY[1, 2, 3, 4], ARRAY[2, 3]), -- Contiguous numeric subsequence
    f2 := CONTAINS_SEQUENCE(ARRAY['a', 'b', 'c'], ARRAY['b', 'c']), -- Contiguous string subsequence
    f3 := CONTAINS_SEQUENCE(ARRAY[1, 2, 3], ARRAY[3, 2]), -- Wrong order is not a match
    f4 := CONTAINS_SEQUENCE(ARRAY[1, 2, 3], ARRAY[]::BIGINT[]) -- Empty sequence argument
;
Result
f1 BOOLEANf2 BOOLEANf3 BOOLEANf4 BOOLEAN
truetruefalsenull

Last update at: 2026/05/26 17:22:09