risingwave icon indicating copy to clipboard operation
risingwave copied to clipboard

feat(expr): conversion from jsonb array into native array

Open xiangjinwu opened this issue 1 year ago • 1 comments

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_elements
    • arr[1] -> js -> 0
    • array_length(arr) -> jsonb_array_length(js)

Additional context

No response

xiangjinwu avatar Jul 09 '24 03:07 xiangjinwu