Last Updated: 5/8/2026
An array type can be created by applying the ARRAY suffix to another
type. For example INT ARRAY is an array of integers. Array indexes
start from 1. Array sizes are limited to 2^31 elements. Array values
be nullable types, e.g., INT ARRAY NULL. Multidimensional arrays
are possible, e.g. VARCHAR ARRAY ARRAY is a two-dimensional array.
In CREATE TABLE and CREATE TYPE declarations there is no way to
specify the nullability of the elements of an ARRAY. The compiler
will always assume that array elements are nullable:
CREATE TABLE T(a INT ARRAY);Table T will have a single column a whose values are nullable
arrays; the array elements will be nullable INT values.
Array literals
Array literals have the syntax ARRAY[expr [,expr]*]. An example
creating a nested array is: ARRAY[ARRAY[1, 2], ARRAY[3, 4]].
The UNNEST SQL Operator
The UNNEST operator takes an ARRAY and returns a table with a
row for each element in the ARRAY: UNNEST(ARRAY) [WITH ORDINALITY]. If the input is an array with 5 elements, the output
is a table with 5 rows, each row holding one element of the array.
The additional keyword WITH ORDINALITY creates an output table
with two columns, where the second column is the index of the element
within the array, with numbering starting at 1. If the array contains
duplicated values, the resulting table will be a multiset.
The UNNEST operator can be used in self-joins as follows:
CREATE TABLE data(CITIES VARCHAR ARRAY, COUNTRY VARCHAR);
CREATE VIEW V AS SELECT city, country
FROM data, UNNEST(cities) AS t (city);The previous query is a shortcut for a CROSS-JOIN query:
CREATE VIEW V AS SELECT city, data.country
FROM data CROSS JOIN UNNEST(data.cities) AS city;UNNEST applied to a NULL value returns an empty table.
Note that applying UNNEST to an ARRAY of structure-typed objects
will produce a collection whose columns are the fields of the
structure, instead of a collection with a single structure-typed
column.
Comparison Operations on Arrays
Comparison operations (=, <>, !=, >, <, >=, <=) in arrays occur lexicographically, from left to right. The elements are compared one by one until a difference is found. Arrays can be compared even if they are different in size.
Examples:
[45] > [22][23, 56, 16] > [23, NULL]