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
Syntax
jsonb_build_array(value, ...)
Parameters
| Parameter | Description |
|---|---|
value |
The elements. |
Return value
jsonb.
Examples
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.
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
| Version | Change |
|---|---|
| PostgreSQL 9.5 | Added |
In other languages
JSON_ARRAY()· SQLite
Related
JSONB_BUILD_OBJECT()· Build a JSON object from alternating keys and values. json_build_object() returns json instead of jsonb.JSONB_AGG()· Aggregate a group's values or rows into a JSON array. json_agg() does the same but returns json.- SQL String Functions · tutorial