proposal: plpgsql - FOREACH t IN JSON ARRAY expr - Mailing list pgsql-hackers

From Pavel Stehule
Subject proposal: plpgsql - FOREACH t IN JSON ARRAY expr
Date
Msg-id CAFj8pRB858EmA2xqaWQMUs_bYmLNZY8eBS2zP+wrg0vyT97gDA@mail.gmail.com
Whole thread Raw
Responses Re: proposal: plpgsql - FOREACH t IN JSON ARRAY expr
List pgsql-hackers
Hi,

last year I did a performance audit of some applications and I found a new relatively common pattern - iteration over jsonb arrays. Because PL/pgSQL doesn't support this iteration directly, they used some combinations of jsonb_array_elements function and FOR IN SELECT.

The overhead of this can be relatively high, and I think we can support FOREACH json(b) arrays without some high cost.

My idea is a support of syntax

FOREACH target IN JSON ARRAY expression LOOP .. END LOOP

target can be a scalar variable of any type - we can use cast rules used in JSON_TABLE

What do you think about this proposal?

Regards

Pavel

pgsql-hackers by date:

Previous
From: David Rowley
Date:
Subject: Re: unnecessary executor overheads around seqscans
Next
From: Álvaro Herrera
Date:
Subject: Re: Converting README documentation to Markdown