From 06237e0bcc9bebf5c5e12e1eb33584ab94b5540b Mon Sep 17 00:00:00 2001 From: Ayush Tiwari Date: Thu, 22 Oct 2026 22:10:20 +0530 Subject: [PATCH v1] Accept empty tsquery in binary input tsqueryrecv() calls findoprnd() even when the input has no query items, so it rejects the binary representation of an empty tsquery, which tsquerysend() produces. This breaks, for example, binary COPY of a table containing an empty tsquery. Skip the operand walk for an empty query, as parse_tsquery() does. Reported-by: Shay Rojansky Author: Ayush Tiwari Bug: #19778 Discussion: https://postgr.es/m/19778-1befc1fba593ab1b@postgresql.org --- src/backend/utils/adt/tsquery.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/backend/utils/adt/tsquery.c b/src/backend/utils/adt/tsquery.c index e4eb7cf5d43..228fa6276be 100644 --- a/src/backend/utils/adt/tsquery.c +++ b/src/backend/utils/adt/tsquery.c @@ -1283,10 +1283,13 @@ tsqueryrecv(PG_FUNCTION_ARGS) * Fill in the left-pointers. Checks that the tree is well-formed as a * side-effect. */ - findoprnd(item, size, &needcleanup); + if (size > 0) + { + findoprnd(item, size, &needcleanup); - /* Can't have found any QI_VALSTOP nodes */ - Assert(!needcleanup); + /* Can't have found any QI_VALSTOP nodes */ + Assert(!needcleanup); + } /* Copy operands to output struct */ for (uint32 i = 0; i < size; i++)