4.15. Array Functions and Operators
Subscript Operator: []
The [] operator is used to access an element of an array, and is indexed starting from one:
SELECT my_array[1] AS first_element
Concatenation Operator: ||
The || operator can be used to concatenate an array with an array or an element of the same type:
SELECT ARRAY [1] || ARRAY [2]; => [1, 2]
SELECT ARRAY [1] || 2; => [1, 2]
SELECT 2 || ARRAY [1]; => [2, 1]
Array Functions
- cardinality(x) → bigint
Returns the cardinality (size) of the array x.
- contains(x, y) → boolean
Returns true iff the array x contains the element y.
- array_sort(x) → array
Sorts and returns the array x. The elements of x must be orderable.
- concat(x, y) → array
Concatenates given arrays x and y. The element types of x and y must be the same. This function provides the same functionality as the concatenation operator (||).