Table 9.48shows the operators available for array types.
Table 9.48. Array Operators
less than or equal
greater than or equal
is contained by
overlap (have elements in common)
Array comparisons compare the array contents element-by-element, using the default B-tree comparison function for the element data type. In multidimensional arrays the elements are visited in row-major order (last subscript varies most rapidly). If the contents of two arrays are equal but the dimensionality is different, the first difference in the dimensionality information determines the sort order. (This is a change from versions ofPostgreSQLprior to 8.2: older versions would claim that two arrays with the same contents were equal, even if the number of dimensions or subscript ranges were different.)
Table 9.49. Array Functions
append an element to the end of an array
concatenate two arrays
returns the number of dimensions of the array
returns a text representation of array's dimensions
returns an array initialized with supplied value and dimensions, optionally with lower bounds other than 1
returns the length of the requested array dimension
returns lower bound of the requested array dimension
returns the subscript of the first occurrence of the second argument in the array, starting at the element indicated by the third argument or at the first element (array must be one-dimensional)
returns an array of subscripts of all occurrences of the second argument in the array given as first argument (array must be one-dimensional)
append an element to the beginning of an array
remove all elements equal to the given value from the array (array must be one-dimensional)
replace each array element equal to the given value with a new value
concatenates array elements using supplied delimiter and optional null string
returns upper bound of the requested array dimension
returns the total number of elements in the array, or 0 if the array is empty
splits string into array elements using supplied delimiter and optional null string
expand an array to a set of rows
expand multiple arrays (possibly of different types) to a set of rows. This is only allowed in the FROM clause; seeSection 126.96.36.199
1 foo2 barNULL baz(3 rows)
array_positions, each array element is compared to the searched value using
IS NOT DISTINCT FROMsemantics.
NULLis returned if the value is not found.
NULLis returned only if the array is
NULL; if the value is not found in the array, an empty array is returned instead.
string_to_array, if the delimiter parameter is NULL, each character in the input string will become a separate element in the resulting array. If the delimiter is an empty string, then the entire input string is returned as a one-element array. Otherwise the input string is split at each occurrence of the delimiter string.
string_to_array, if the null-string parameter is omitted or NULL, none of the substrings of the input will be replaced by NULL. In
array_to_string, if the null-string parameter is omitted or NULL, any null elements in the array are simply skipped and not represented in the output string.
There are two differences in the behavior of
string_to_arrayfrom pre-9.1 versions ofPostgreSQL. First, it will return an empty (zero-element) array rather than NULL when the input string is of zero length. Second, if the delimiter string is NULL, the function splits the input into individual characters, rather than returning NULL as before.
See alsoSection 9.20about the aggregate function
array_aggfor use with arrays.