risingwave
risingwave copied to clipboard
feat(expr): conversion from jsonb array into native array
Is your feature request related to a problem? Please describe.
Given '[3, 1, 7]'::jsonb, what is the recommended way to convert it into a native array[3, 1, 7]::int[]?
Describe the solution you'd like
No option is preferred than the others. See below for all the candidates.
Describe alternatives you've considered
- Cast
jsonb -> T[]. For example'[3, 1, 7]'::jsonb::int[] - Unnest and agg with subquery-expr:
select array_agg(jsonb_array_elements::int order by ordinality) from jsonb_array_elements('[3, 1, 7]'::jsonb) with ordinality
- Avoid conversion and just use the corresponding jsonb operations directly
unnest->jsonb_array_elementsarr[1]->js -> 0array_length(arr)->jsonb_array_length(js)
Additional context
No response