postgres.git / summary / log / commit / refs
commit 0d0d2a13e8b60f66017836ded0c05b5907921bf0
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: Thu Oct 22 17:51:27 2026 +0000
First released in: 14.25, 15.20, 16.16, 17.12, 18.7, 19.0
Accept empty tsquery in binary input.
tsqueryrecv() calls findoprnd() even when the input has no query
items, so it fails on an empty tsquery, which is legal data.
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.
Bug: #19778
Reported-by: Shay Rojansky <roji@roji.org>
Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/19778-1befc1fba593ab1b@postgresql.org
Backpatch-through: 14
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 ec81c3d681e..0677914acce 100644
--- a/src/backend/utils/adt/tsquery.c
+++ b/src/backend/utils/adt/tsquery.c
@@ -1343,10 +1343,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 (i = 0; i < size; i++)
[parent: df34fdf3f594]