Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Native arrays

Amphi supports one-dimensional, homogeneous, typed arrays. Elements may be bool, bytea, int2, int4, int8, text, float8, uuid, or numeric.

Each element type has a corresponding array type identity in the catalog — for example, int4 and int4[]. The array implementation is shared and parameterized by the element type; the catalog distinction is required for operator, cast, and protocol resolution. The catalog stores element-to-array and array-to-element links, following PostgreSQL’s typelem/typarray model.

Construction and access

SELECT ARRAY[10, 20, NULL]::int4[];
SELECT (ARRAY[10, 20, 30])[2];       -- 20
SELECT (ARRAY[10, 20, 30, 40])[2:3]; -- {20, 30}
SELECT ARRAY[]::int4[];               -- typed empty array

Indexes are one-based. A NULL or out-of-range index returns NULL. Slices accept omitted bounds and are clamped to the array size. ARRAY[] needs an explicit cast.

unnest, ANY, and ALL

unnest(array) returns one row per element and preserves NULL elements. Scalar operators can compare against an array, for example 2 = ANY (ARRAY[1, 2, 3]). Empty ANY is false and empty ALL is true; NULL elements follow SQL three-valued logic.

Arrays are also used as cycle paths by WITH RECURSIVE ... CYCLE. Multidimensional arrays and types without a native codec are not currently supported.