PostgreSQL supports columns to defined as an array. This array is of a variable length and can be defined as a one-dimensional or multidimensional array. You can create an array of any datatype, such as text, integer, or composite type, by appending []
at the end of the type. For example, you can declare an array of an integer type by using int[]
or character data by using text[]
. This array support in PostgreSQL helps build aggregate functions using IN
and ANY
clauses. We will explore its use in a later section.
An array can be created with the help of an ARRAY
keyword comprising the list of expressions enclosed in square brackets:
SELECT ARRAY[1,2,3] AS sample_array;
Output
Sample_array
------- --------- ---
{1,2,3}
By default, the datatype of the preceding array will be an integer as it is the common datatype for all members of sample_array
. You can explicitly override the array datatype to the other datatype by using the...