PostgreSQL arrays
Multidimensional arrays are supported; here, the array type can be a base, enum, or composite type. Array elements should have only one data type. PostgreSQL arrays allow duplicate values as well as null values. The following example shows how to initialize a one-dimensional array and get the first element:
SELECT ('{red, green, blue}'::text[])[1] as red ; red ----- red (1 row)
The array length, by default, is not bound to a certain value, but this can also be specified when using arrays to define a relation. By default, an array index, as shown in the preceding example, starts from index one; however, this behavior can be changed by defining the dimension when initializing the array, as follows:
car_portal=# SELECT '[0:1]={1,2}'::INT[]; int4 ------------- [0:1]={1,2} (1 row) car_portal=# SELECT ('[0:1]={1,2}'::INT[])[0]; int4 ------ 1 (1 row) car_portal=# SELECT ('[0:1]={1,2}'::INT[])[1]; int4 ------ 2 (1 row)
Arrays can be initialized using the {}
construct...