An array can also be constructed by using the functions
array_prepend,array_append, orarray_cat. The first two only support one-dimensional arrays, but array_cat supports multidimensional arrays. Note that the concatenation operator discussed above is preferred over direct use of these functions. In fact, these functions primarily exist for use in implementing the concatenation operator. However, they might be directly useful in the creation of user-defined aggregates.
Examples:
SELECT array_prepend(1, ARRAY[2,3]);
array_prepend
---------------
{1,2,3}
(1 row)
SELECT array_append(ARRAY[1,2], 3);
array_append
--------------
{1,2,3}
(1 row)Although, the docs recommend using a concatenation operator instead. From docs:
The concatenation operator allows a single element to be pushed onto the beginning or end of a one-dimensional array.
Examples:
SELECT array_dims(1 || '[0:1]={2,3}'::int[]);
array_dims
------------
[0:2]
(1 row)
SELECT array_dims(ARRAY[1,2] || 3);
array_dims
------------
[1:3]
(1 row)
SELECT array_dims(ARRAY[1,2] || ARRAY[2,4]);
array_dims|
----------+
[1:4] |
SELECT ARRAY[1,2] || ARRAY[2,4];
?column? |
---------+
{1,2,2,4}|Note: array_dims takes an array and returns a text representation of array’s dimensions. From array-functions-table