PostgreSQL jsonb_array_elements_text() Function

The PostgreSQL jsonb_array_elements_text() function expands the top-level JSONB array into a set of text values.

This function is similar to the jsonb_array_elements function, except that the items in the set returned by the jsonb_array_elements function are of type JSONB.

jsonb_array_elements_text() Syntax

This is the syntax of the PostgreSQL jsonb_array_elements_text() function:

jsonb_array_elements_text(any_array JSONB) -> SETOF TEXT

Parameters

any_array

Required. A JSONB array.

Return value

The PostgreSQL jsonb_array_elements_text() function returns a set including all text values representing all the top-level elements in the JSONB array specified by the parameter.

jsonb_array_elements_text() Examples

This example shows how to use the PostgreSQL jsonb_array_elements_text() function to expand a JSONB array into a set of text values.

SELECT jsonb_array_elements_text('[1, 2, [3, 4]]');
 jsonb_array_elements_text
--------------------------
 1
 2
 [3, 4]

Since the jsonb_array_elements_text() function return value is of type SETOF, you can use jsonb_array_elements_text() as a temporary table in the SELECT * FROM statement:

SELECT * FROM jsonb_array_elements_text('[1, 2, [3, 4]]');
 value
--------
 1
 2
 [3, 4]