Arrays

An array is a data structure consisting of a collection of elements (values or variables), the order of the elements in the array is significant and each element in the array is identified by an index. The index of the the array is often started by 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; 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:

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

Get Learning PostgreSQL 10 - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.