Re: jsonb_array_elements_recursive()

2021-02-07 Thread David G. Johnston
On Sun, Feb 7, 2021 at 11:39 AM Pavel Stehule wrote: > > > ne 7. 2. 2021 v 19:18 odesílatel Zhihong Yu napsal: > >> Hi, >> >> bq. SELECT unnest('[[5,2],"a",[8,[3,2],6]]'::jsonb); >> >> Since the array without cast is not normal array (and would be rejected), >> I wonder if the cast is needed. >>

Re: jsonb_array_elements_recursive()

2021-02-07 Thread Pavel Stehule
ne 7. 2. 2021 v 19:18 odesílatel Zhihong Yu napsal: > Hi, > > bq. SELECT unnest('[[5,2],"a",[8,[3,2],6]]'::jsonb); > > 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.

Re: jsonb_array_elements_recursive()

2021-02-07 Thread Zhihong Yu
Hi, bq. SELECT unnest('[[5,2],"a",[8,[3,2],6]]'::jsonb); 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 wrote: >

Re: jsonb_array_elements_recursive()

2021-02-07 Thread Pavel Stehule
ne 7. 2. 2021 v 18:43 odesílatel Joel Jacobson napsal: > 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]]

Re: jsonb_array_elements_recursive()

2021-02-07 Thread Joel Jacobson
On Sun, Feb 7, 2021, at 18:42, Joel Jacobson wrote: >SELECT pit.jsonb_array_elements_recursive(value); Sorry, that line should have been: SELECT unnest(value);

Re: jsonb_array_elements_recursive()

2021-02-07 Thread Joel Jacobson
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

Re: jsonb_array_elements_recursive()

2021-02-07 Thread David G. Johnston
On Sunday, February 7, 2021, 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 th

Re: jsonb_array_elements_recursive()

2021-02-07 Thread Pavel Stehule
Hi ne 7. 2. 2021 v 18:31 odesílatel Zhihong Yu napsal: > 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

Re: jsonb_array_elements_recursive()

2021-02-07 Thread Zhihong Yu
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 ? Cheers On Sun, Feb 7, 2021 at 8:31 AM Joel Jacobs

Re: jsonb_array_elements_recursive()

2021-02-07 Thread Joel Jacobson
On Sun, Feb 7, 2021, at 17:27, Tom Lane wrote: >"Joel Jacobson" writes: >> Having thought about this some more, >> the function name should of course be jsonb_unnest(), >> similar to how unnest() works for normal arrays: > >Why not just unnest(), then? > >regards, tom lane Ahh, of course! I total

Re: jsonb_array_elements_recursive()

2021-02-07 Thread Joel Jacobson
On Sun, Feb 7, 2021, at 17:08, Pavel Stehule wrote: >>ne 7. 2. 2021 v 16:59 odesílatel Joel Jacobson napsal: >> >>SELECT jsonb_unnest('[[3,2],[1,4]]'::jsonb); >>jsonb_unnest >> >>3 >>2 >>1 >>4 >>(4 rows) > >It has sense. Maybe it should return two columns - first path to valu

Re: jsonb_array_elements_recursive()

2021-02-07 Thread Tom Lane
"Joel Jacobson" writes: > Having thought about this some more, > the function name should of course be jsonb_unnest(), > similar to how unnest() works for normal arrays: Why not just unnest(), then? regards, tom lane

Re: jsonb_array_elements_recursive()

2021-02-07 Thread Pavel Stehule
Hi ne 7. 2. 2021 v 16:59 odesílatel Joel Jacobson napsal: > Having thought about this some more, > the function name should of course be jsonb_unnest(), > similar to how unnest() works for normal arrays: > > SELECT unnest(array[[3,2],[1,4]]); > unnest > > 3 > 2 > 1 >

Re: jsonb_array_elements_recursive()

2021-02-07 Thread Joel Jacobson
Having thought about this some more, the function name should of course be jsonb_unnest(), similar to how unnest() works for normal arrays: SELECT unnest(array[[3,2],[1,4]]); unnest 3 2 1 4 (4 rows) SELECT jsonb_unnest('[[3,2],[1,4]]'::jsonb); jsonb_unnest ---

jsonb_array_elements_recursive()

2021-02-07 Thread Joel Jacobson
t's common enough to motivate a new param: jsonb_array_elements(from_json jsonb [, recursive boolean ]) Or as a separate function. Below is a PoC in PL/pgSQL: CREATE OR REPLACE FUNCTION jsonb_array_elements_recursive(from_json jsonb, OUT value jsonb) RETURNS SETOF jsonb LANGUAGE plpgsql