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
| Parameter | Type | Required | Description |
|---|---|---|---|
array | ARRAY<T> | Yes | The array to search within |
sequence | ARRAY<T> | Yes | The contiguous sequence to find |
Notes
- Checks for contiguous subsequence match
- Elements must appear in order without gaps
- Returns FALSE if sequence is not found
- Every array contains the empty sequence, so an empty
sequenceis TRUE - A NULL element matches only a NULL element, so a gap is not a match
- Uses element equality comparison
See also
Examples
FeatureQL
RETURN
-- Contiguous numeric subsequence
f1 := CONTAINS_SEQUENCE(ARRAY(1, 2, 3, 4), ARRAY(2, 3)),
-- Contiguous string subsequence
f2 := CONTAINS_SEQUENCE(ARRAY('a', 'b', 'c'), ARRAY('b', 'c')),
-- Wrong order is not a match
f3 := CONTAINS_SEQUENCE(ARRAY(1, 2, 3), ARRAY(3, 2)),
-- Empty sequence argument
f4 := CONTAINS_SEQUENCE(ARRAY(1, 2, 3), ARRAY()::ARRAY<BIGINT>)
;Result
| f1 BOOLEAN | f2 BOOLEAN | f3 BOOLEAN | f4 BOOLEAN |
|---|---|---|---|
| true | true | false | true |
On this page