public inbox for [email protected]  
help / color / mirror / Atom feed
From: Jim Jones <[email protected]>
To: Pavel Stehule <[email protected]>
Cc: PostgreSQL Hackers <[email protected]>
Subject: Re: POC: PLpgSQL FOREACH IN JSON ARRAY
Date: Wed, 4 Mar 2026 12:35:17 +0100
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAFj8pRDi-7S7cWgtsvdHm8vvhvd8xHQ7tdXymBfBQQgpYangPQ@mail.gmail.com>
References: <CAFj8pRD9Jjv+m=6DP6vWWn5NnZeTPH9eoPFCnA1JE5hRKRDMxQ@mail.gmail.com>
	<CAFj8pRCBUtakcgBF2uZ-+2rq9Kzw-p0V1i6B73gfiVjwKct3AQ@mail.gmail.com>
	<CAFj8pRA7TLOTuY-Dry2SaSpaPaqUJpsJke8Bm2SyZaVh2p5y4Q@mail.gmail.com>
	<[email protected]>
	<CAFj8pRDi-7S7cWgtsvdHm8vvhvd8xHQ7tdXymBfBQQgpYangPQ@mail.gmail.com>

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;
$$;


Thanks!

Best, Jim





reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: POC: PLpgSQL FOREACH IN JSON ARRAY
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox