Re: POC: PLpgSQL FOREACH IN JSON ARRAY
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Pavel Stehule <pavel.stehule@gmail.com>
Cc: Peter Eisentraut <peter@eisentraut.org>,
PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2026-07-01T21:40:04Z
Lists: pgsql-hackers
I took a very quick look through the v20260616 patch. I think you need to work harder on the separation of knowledge. In particular I don't like that the type-specific setup routines (create_foreach_a_array_iterator etc) contain so many assumptions that they are being called from a PLpgsql FOREACH statement and nothing else. IMO the point of putting this into the SubscriptRoutines infrastructure is to make a general-purpose facility that could be used by different things. So: * it's not clear to me that these routines have any business knowing about the "target type"; they certainly shouldn't contain comments alluding to PLpgSQL's conversion abilities. I think probably you just want them to pass back the data type they are producing and let PLpgSQL decide whether it wants to convert or not. * we need to think about how the error messages could be phrased more generically, or else not have these functions throw those errors themselves but instead pass back an error code that the caller could use to select an error message. I suspect this will end up with visible changes in the error messages produced by existing cases, and that's okay IMO. * memory management may need to be rethought a bit as well. Certainly the comments referencing exec_eval_cleanup do not belong here. regards, tom lane