ARRAY_POSITIONS

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Returns an array of the indices of all occurrences of a specified value.

Syntax

array_positions(<array>, <value>)

Arguments

Required

  • <array>: The array to search.
  • <value>: The value to find (must match array element type).

Returns

Returns an array of integers that represents all 1-based indices where the value occurs, or an empty array if not found.

Examples

Find All Occurrences

Find all positions of a value that appears multiple times.

SELECT array_positions(array[1, 3, 4, 3], 3) AS positions;

Returns [2, 4], an array of indices where 3 appears in the array.

Value Not Found

Attempt to find positions of a value that doesn't exist.

SELECT array_positions(array[1, 3, 4, 3], 2) AS positions;

Returns [], an empty array, because 2 isn't present in the array.

Related Documentation