PostgreSQL: Array Functions and Operators
I kind of skipped over the functions/operators section of the PostgreSQL documentation when reading it. I want to review the sections that I think would be useful to me.
References
Notes
The below tables shows the specialized operators available for array types. In addition to those, the usual comparison operators are available for arrays. The comparison operators compare the array contents element-by-element, using the default B-tree comparison function for the element data type, and sort based on the first difference. In multidimensional arrays the elements are visited in row major order. If the contents of two arrays are equal but the dimensionality is different, the first difference in the dimensionality information determines the sort order.
Operator Description Example(s) |
---|
Does the first array contain the second, that is, does each element appearing in the second array equal some element of the first array? (Duplicates are not treated specially, thus
|
Is the first array contained by the second?
|
Do the arrays overlap, that is, have any elements in common?
|
Concatenates the two arrays. Concatenating a null or empty array is a no-op; otherwise the arrays must have the same number of dimensions (as illustrated by the first example) or differ in number of dimensions by one (as illustrated by the second). If the arrays are not of identical element types, they will be coerced to a common type (see Section 10.5).
|
Concatenates an element onto the front of an array (which must be empty or one-dimensional).
|
Concatenates an element onto the end of an array (which must be empty or one-dimensional).
|
The table below shows some of the functions available for array types.
Function Description Example(s) |
---|
Appends an element to the end of an array (same as the
|
Concatenates two arrays (same as the
|
Returns a text representation of the array's dimensions.
|
Returns an array filled with copies of the given value, having dimensions of the lengths specified by the second argument. The optional third argument supplies lower-bound values for each dimension (which default to all
|
Returns the length of the requested array dimension. (Produces NULL instead of 0 for empty or missing array dimensions.)
|
Returns the lower bound of the requested array dimension.
|
Returns the number of dimensions of the array.
|
Returns the subscript of the first occurrence of the second argument in the array, or
|
Returns an array of the subscripts of all occurrences of the second argument in the array given as first argument. The array must be one-dimensional. Comparisons are done using
|
Prepends an element to the beginning of an array (same as the
|
Removes all elements equal to the given value from the array. The array must be one-dimensional. Comparisons are done using
|
Replaces each array element equal to the second argument with the third argument.
|
Returns an array of
|
Randomly shuffles the first dimension of the array.
|
Converts each array element to its text representation, and concatenates those separated by the
|
Returns the upper bound of the requested array dimension.
|
Returns the total number of elements in the array, or 0 if the array is empty.
|
Trims an array by removing the last
|
Expands an array into a set of rows. The array's elements are read out in storage order.
|
Expands multiple arrays (possibly of different data types) into a set of rows. If the arrays are not all the same length then the shorter ones are padded with
|
Comments
You have to be logged in to add a comment
User Comments
There are currently no comments for this article.