Materialize Logo

jsonb_agg Function

The jsonb_agg(expression) function aggregates all values indicated by its expression, returning the values (including nulls) as a jsonb array.

Signatures

Parameter Type Description
expression jsonb The values you want aggregated.

Return value

jsonb_agg returns the aggregated values as a jsonb array.

Details

Usage in dataflows

While jsonb_agg is available in Materialize, materializing jsonb_agg(expression) is considered an incremental view maintenance anti-pattern. Any change to the data underlying the function call will require the function to be recomputed entirely, discarding the benefits of maintaining incremental updates.

Instead, we recommend that you materialize all components required for the jsonb_agg function call and create a non-materialized view using jsonb_agg on top of that. That pattern is illustrated in the following statements:

CREATE MATERIALIZED VIEW foo_view AS SELECT * FROM foo;
CREATE VIEW bar AS jsonb_agg(foo_view.bar);

Examples

SELECT jsonb_agg(1);
 jsonb_agg
-----------
 [1]

SELECT jsonb_agg('example'::text);
  jsonb_agg
-------------
 ["example"]

See also

Did this info help?
Yes No