Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wf2fP-005DzP-0R for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Jul 2026 21:40:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wf2fN-00FpRT-3A for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Jul 2026 21:40:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wf2fN-00FpRL-2I for pgsql-hackers@lists.postgresql.org; Wed, 01 Jul 2026 21:40:21 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wf2fL-00000001Gzx-1vWH for pgsql-hackers@lists.postgresql.org; Wed, 01 Jul 2026 21:40:21 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 661Le4r13648849; Wed, 1 Jul 2026 17:40:04 -0400 From: Tom Lane To: Pavel Stehule cc: Peter Eisentraut , PostgreSQL Hackers Subject: Re: POC: PLpgSQL FOREACH IN JSON ARRAY In-reply-to: References: <4166.1773289811@sss.pgh.pa.us> Comments: In-reply-to Pavel Stehule message dated "Tue, 16 Jun 2026 09:52:59 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3648847.1782942004.1@sss.pgh.pa.us> Date: Wed, 01 Jul 2026 17:40:04 -0400 Message-ID: <3648848.1782942004@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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