Arrays

An array is a data structure that consists of a collection of elements (values or variables); the order of the elements in the array significant and each element in the array is identified by an index. The index of the array is often starts at 1, but in some programming languages, such as C and C++, the index starts at 0. Array elements should have the same type, such as INT or TEXT

Multidimensional arrays are supported; 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:

car_portal=> SELECT ('{red, green, blue}'::text[])[1] ...

Get Learning PostgreSQL 11 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.