From: Tom Lane <tgl@sss.pgh.pa.us>
To: Aleksander Alekseev <aleksander@tigerdata.com>
Cc: pgsql-bugs@lists.postgresql.org
Cc: exclusion@gmail.com
Subject: Re: BUG #18984: Empty prepared statement from psql \parse triggers assert in PortalRunMulti
Date: Mon, 14 Jul 2025 17:40:22 -0400
Message-ID: <743115.1752529222@sss.pgh.pa.us> (raw)
In-Reply-To: <CAJ7c6TOoGUosKwdXt1LwJpThvP2-ZNpuv0H=owYdp6omwQ=keA@mail.gmail.com>
References: <18984-0f4778a6599ac3ae@postgresql.org>
<715434.1752521761@sss.pgh.pa.us>
<CAJ7c6TOoGUosKwdXt1LwJpThvP2-ZNpuv0H=owYdp6omwQ=keA@mail.gmail.com>
Aleksander Alekseev <aleksander@tigerdata.com> 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
Attachments:
[text/x-diff] wip-avoid-failure-with-empty-prepared-query.patch (481B, ../743115.1752529222@sss.pgh.pa.us/2-wip-avoid-failure-with-empty-prepared-query.patch)
download | inline diff:diff --git a/src/backend/tcop/pquery.c b/src/backend/tcop/pquery.cindex 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;
}
}
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: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, aleksander@tigerdata.com, 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: <743115.1752529222@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox