PostgreSQL 18 reference · JSON Functions

PostgreSQL JSONB_BUILD_ARRAY() Function

Build a JSON array from the arguments, which may be of different types.

PostgreSQL 18 Since 9.5

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

jsonb_build_array(value, ...)

Parameters

ParameterDescription
value The elements.

Return value

jsonb.

Examples

Mixed types
SELECT jsonb_build_array(1, 'two', NULL, true) AS arr;

Output

          arr
------------------------
 [1, "two", null, true]
(1 row)

Run this on your computer — see “Get Started” for setup.

From columns
SELECT jsonb_build_array(name, price) AS pair FROM products LIMIT 2;

Output

             pair
------------------------------
 ["SQL for Beginners", 29.99]
 ["Clean Code", 37.50]
(2 rows)

Run this on your computer — see “Get Started” for setup.

Version history

VersionChange
PostgreSQL 9.5Added

In other languages

Was this page helpful?