Re: jsonb_array_elements_recursive()
От | Zhihong Yu |
---|---|
Тема | Re: jsonb_array_elements_recursive() |
Дата | |
Msg-id | CALNJ-vSzDD7+MBoSCKXz323Arh8RcvVo=OgpcRaWVxLoi9e1zQ@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: jsonb_array_elements_recursive() ("Joel Jacobson" <joel@compiler.org>) |
Ответы |
Re: jsonb_array_elements_recursive()
|
Список | pgsql-hackers |
Hi,
Since the array without cast is not normal array (and would be rejected), I wonder if the cast is needed.
Because casting to jsonb is the only legitimate interpretation here.
Cheers
On Sun, Feb 7, 2021 at 9:42 AM Joel Jacobson <joel@compiler.org> wrote:
On Sun, Feb 7, 2021, at 18:33, Zhihong Yu wrote:>Hi,># SELECT '[[5,2],"a",[8,[3,2],6]]'::jsonb;> jsonb>-------------------------------> [[5, 2], "a", [8, [3, 2], 6]]>(1 row)>>unnest(array[[3,2],"a",[1,4]]) is not accepted currently.>>Would the enhanced unnest accept the above array ?>>CheersYes, but only if the overloaded jsonb version of unnest() exists,and only if it's a jsonb array, not a normal array, like Pavel explained.Your example using a PoC PL/pgSQL:CREATE FUNCTION unnest(jsonb)RETURNS SETOF jsonbLANGUAGE plpgsqlAS $$DECLAREvalue jsonb;BEGINFOR value IN SELECT jsonb_array_elements($1) LOOPIF jsonb_typeof(value) <> 'array' THENRETURN NEXT value;ELSERETURN QUERYSELECT pit.jsonb_array_elements_recursive(value);END IF;END LOOP;END$$;SELECT unnest('[[5,2],"a",[8,[3,2],6]]'::jsonb);unnest--------52"a"8326(7 rows)Cheers,/Joel
В списке pgsql-hackers по дате отправления: