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.94.2) (envelope-from ) id 1ubQuS-000kWr-Cm for pgsql-bugs@arkaria.postgresql.org; Mon, 14 Jul 2025 21:40:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1ubQuQ-00EEKk-AK for pgsql-bugs@arkaria.postgresql.org; Mon, 14 Jul 2025 21:40:26 +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.94.2) (envelope-from ) id 1ubQuQ-00EEKc-16 for pgsql-bugs@lists.postgresql.org; Mon, 14 Jul 2025 21:40:26 +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.96) (envelope-from ) id 1ubQuO-007klH-1W for pgsql-bugs@lists.postgresql.org; Mon, 14 Jul 2025 21:40:26 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 56ELeMiU743116; Mon, 14 Jul 2025 17:40:22 -0400 From: Tom Lane To: Aleksander Alekseev cc: pgsql-bugs@lists.postgresql.org, exclusion@gmail.com Subject: Re: BUG #18984: Empty prepared statement from psql \parse triggers assert in PortalRunMulti In-reply-to: References: <18984-0f4778a6599ac3ae@postgresql.org> <715434.1752521761@sss.pgh.pa.us> Comments: In-reply-to Aleksander Alekseev message dated "Tue, 15 Jul 2025 00:11:31 +0300" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <742862.1752529035.0@sss.pgh.pa.us> Date: Mon, 14 Jul 2025 17:40:22 -0400 Message-ID: <743115.1752529222@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <742862.1752529035.1@sss.pgh.pa.us> Aleksander Alekseev writes: >> That being the case, maybe we should band-aid this by returning >> EXECUTE if the prepared statement is empty. > This sounds pretty straightforward and seems to solve the problem. > Patch attached. Hmm, throwing an error is exactly not what I was suggesting above. The attached quick draft (needs attention to comments) results in regression=# \parse s regression=# execute s; EXECUTE which matches the behavior of pre-v12 servers. (BTW, I wonder why psql is emitting an extra newline after \parse.) regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="wip-avoid-failure-with-empty-prepared-query.patch"; charset="us-ascii" Content-ID: <742862.1752529035.2@sss.pgh.pa.us> Content-Description: wip-avoid-failure-with-empty-prepared-query.patch diff --git a/src/backend/tcop/pquery.c b/src/backend/tcop/pquery.c index d1593f38b35..2d998e87846 100644 --- a/src/backend/tcop/pquery.c +++ b/src/backend/tcop/pquery.c @@ -1365,8 +1365,8 @@ PortalRunMulti(Portal portal, { if (portal->qc.commandTag != CMDTAG_UNKNOWN) CopyQueryCompletion(qc, &portal->qc); - /* If the caller supplied a qc, we should have set it by now. */ - Assert(qc->commandTag != CMDTAG_UNKNOWN); + else + qc->commandTag = CMDTAG_EXECUTE; } } ------- =_aaaaaaaaaa0--