Home > Mobile >  PostgreSQL How to convert JSONB array of arrays to pg array of arrays?
PostgreSQL How to convert JSONB array of arrays to pg array of arrays?

Time:08-15

I have options JSONB field:

enter image description here

And I can get JSONB array:

SELECT "options" FROM "products";

->

'[["black", "2"], ["white", "7"]]'::JSONB

But, How can I make array of arrays?

->

ARRAY[ARRAY['black', '2'], ARRAY['white', '7']]

CodePudding user response:

select (
  select array_agg(
    (select array_agg(s) from jsonb_array_elements_text(a) j2(s))
  ) from jsonb_array_elements(options) j1(a)
) from products
  • Related