array_split() function

The array_split() function parses the input for elements, which are separated by a delimiter, to create an array.

Syntax

The array_split() function has the following syntax:
array = array_split(varchar input, varchar delimiter [, [int type]);
array = array_split(nvarchar input, nchar delimiter [, [int type]);

The input value specifies a character-delimited list of elements.

The delimiter value specifies the delimiter that is used in the input.

The optional type value specifies the type of the array; the type defaults to 8 (varchar). For other values, see Table 1.

Returns

The function creates an array.

Example

For example, the following query creates an array from the input string, where the comma character delimits each array value:
select array_split('1,2,3,4,5,6,7,8',',');
 array_split 
-------------
 ARR
(1 row)
To view the elements of the array, you can use a query such as the following one:
select array_combine(array_split('1,2,3,4,5,6,7,8',','),'|');
The query returns the following information:
 array_combine  
-----------------
 1|2|3|4|5|6|7|8
(1 row)