all-things-risingwave
How to build a JSON object in RisingWave without jsonb_build_object function?
I need to build a JSON object in RisingWave but the jsonb_build_object function is not available. What alternative methods can I use to construct a JSON object in RisingWave?
Ch
Charlie
Asked on Oct 16, 2023
- The jsonb_build_object function is not currently available in RisingWave.
- One alternative method is to construct a JSON object by building a text object and casting it to jsonb.
with queryA as (
select
'{ "id": "' || id::text || '", "name": "' || name::text || '" }' as a_row
from
tableA
),
jsonified as (
select
'{ "a": ' || a_row || ' }' as nested
from
queryA
)
select
nested::jsonb
from
jsonified
;```
- This method requires knowing the shape of the columns and appropriately serializing each column into a text object before casting it to jsonb.
- While this workaround may not be ideal, it can help in constructing JSON objects until support for jsonb_build_object is added in RisingWave.
Nov 20, 2023Edited by