Re: POC: PLpgSQL FOREACH IN JSON ARRAY

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: POC: PLpgSQL FOREACH IN JSON ARRAY
Date: 2026-03-04 18:50:34
Message-ID: CAFj8pRA-GKmYig4A23mUyCxEquYPK_t2acg0s_KHWhadh_w5MA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi

st 4. 3. 2026 v 12:35 odesílatel Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>
napsal:

> I reviewed the code I have nothing to add at this point. LGTM!
>
> The tests touch a lot of different scenarios, but for the sake of
> completeness I'd like to suggest adding these three cases:
>
> -- EXIT and CONTINUE can be triggered by LOOP_RC_PROCESSING
> DO $$
> DECLARE x int;
> BEGIN
> FOREACH x IN JSON ARRAY '[1,2,3,4,5]'
> LOOP
> EXIT WHEN x = 3;
> RAISE NOTICE '%', x;
> END LOOP;
> END;
> $$;
>
> DO $$
> DECLARE x int;
> BEGIN
> FOREACH x IN JSON ARRAY '[1,2,3,4,5]'
> LOOP
> CONTINUE WHEN x % 2 = 0;
> RAISE NOTICE '%', x;
> END LOOP;
> END;
> $$;
>
>
> -- Variable instead of string
> DO $$
> DECLARE x int; arr jsonb;
> BEGIN
> SELECT jsonb_agg(i) INTO arr
> FROM generate_series(1,3) i;
>
> FOREACH x IN JSON ARRAY arr
> LOOP
> RAISE NOTICE '%', x;
> END LOOP;
> END;
> $$;
>
>
I merged these examples to tests

Thank you for review

Regards

Pavel

>
> Thanks!
>
> Best, Jim
>

Attachment Content-Type Size
v20260304-5-0001-FOREACH-scalar-IN-JSON-ARRAY.patch text/x-patch 32.0 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Maciek Sakrejda 2026-03-04 19:11:12 Re: V18 change on EXPLAIN ANALYZE
Previous Message Tom Lane 2026-03-04 18:45:35 Re: Fix errno handling in popen_check() to avoid false error reports