POSEXPLODE converts an array into a two-column table: pos (zero-based index) and val (element value).
Syntax
posexplode(array<T> <a>)Parameters
| Parameter | Required | Description |
|---|---|---|
a | Yes | An array of any element type. T in array<T> represents the element data type. |
Return value
Returns a table with two columns:
| Column | Description |
|---|---|
pos | The zero-based position of the element in the array. |
val | The element value. |
Examples
Expand an array
SELECT posexplode(ARRAY('a', 'c', 'f', 'b'));Result:
+-----+-----+
| pos | val |
+-----+-----+
| 0 | a |
| 1 | c |
| 2 | f |
| 3 | b |
+-----+-----+Related functions
POSEXPLODE is a complex type function. For more information about functions that process ARRAY, MAP, STRUCT, and JSON data, see Complex type functions.