Skip to content
Advertisement

How to convert integer[] to jsonb in a PL/pgSQL code block

How to convert integer[] to jsonb?

Advertisement

Answer

Use to_jsonb():

Or:

array_to_json() is only still useful to get line feeds in json (not jsonb!). The manual:

Converts an SQL array to a JSON array. The behavior is the same as to_json except that line feeds will be added between top-level array elements if the optional boolean parameter is true.

See:

To convert back:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement