Introduction to arrays

PostgreSQL supports columns to defined as an  array. This array is of a variable length and can be defined as a one-dimensional or multidimensional array. You can create an array of any datatype, such as text, integer, or composite type, by appending [] at the end of the type. For example, you can declare an array of an integer type by using int[] or character data by using text[]. This array support in PostgreSQL helps build aggregate functions using IN and ANY clauses. We will explore its use in a later section.

Array constructors

An array can be created with the help of an ARRAY keyword comprising the list of expressions enclosed in square brackets:

SELECT ARRAY[1,2,3] AS sample_array; Output Sample_array ------- --------- ...

Get PostgreSQL Development Essentials 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.