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.98.2) (envelope-from ) id 1xJmBR-00000000QYI-0ryz for pgsql-bugs@arkaria.postgresql.org; Thu, 22 Oct 2026 06:21:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xJmBO-00000009A7C-39mJ for pgsql-bugs@arkaria.postgresql.org; Thu, 22 Oct 2026 06:21:46 +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.98.2) (envelope-from ) id 1xJFSP-00000001hjN-3ZO3 for pgsql-bugs@lists.postgresql.org; Tue, 20 Oct 2026 19:25:09 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xJFSM-000000003rz-38Lv for pgsql-bugs@lists.postgresql.org; Tue, 20 Oct 2026 19:25:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=mPOO6MVrPF66jm41J7V26IVGafRlZNWUR4T0dOItsRY=; b=01ivoAS+ahf4mb7/keq11WsEQZ VIbMTHyjFSlzNiRdt8CsBcO0g3gdJuljrPwHnbgL4SOyMaTsBwP8fFG6XaCT8S5WfV6rX4PzMBCZ4 qPoNOXeNUVoPECcCzo3b0Oh2B001pG5kd9U89St9HdH6kipCNuNgggs03O9vqEuky/iDRU7H6jna5 d4/7Nw/dkgAAgOn18FwUuMURWnIlWEc1eEbKl14tGDjG06L0Xeu8JB85Y7HI1Pq26rxUOTT6BIqv0 yDdcgCo7i1xqHFwL6z3oHmNAqqs2FBQAeEwwnAsadtRBv8yKhv/D3Lph+QQeeoum/uebRxhVLVitA LFtFkEWg==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xJFSL-00000000A4i-33LZ for pgsql-bugs@lists.postgresql.org; Tue, 20 Oct 2026 19:25:05 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xJFSK-00000000eTz-04bd for pgsql-bugs@lists.postgresql.org; Tue, 20 Oct 2026 19:25:04 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19778: Empty tsquery cannot roundtrip through binary input To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: roji@roji.org Reply-To: roji@roji.org, pgsql-bugs@lists.postgresql.org Date: Tue, 20 Oct 2026 19:24:37 +0000 Message-ID: <19778-1befc1fba593ab1b@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19778 Logged by: Shay Rojansky Email address: roji@roji.org PostgreSQL version: 18.4 Operating system: macOS Tahoe 26.7.1 Description: =20 It appears that an empty binary tsquery cannot be written to PostgreSQL. Writing a non-empty binary tsquery works, as well as writing an empty text tsquery. Minimal repro: #include #include #include #include static void require_row(PGresult *result) { if (PQresultStatus(result) !=3D PGRES_TUPLES_OK || PQntuples(result) != =3D 1) { fprintf(stderr, "Unexpected result: %s", PQresultErrorMessage(result)); exit(1); } } int main(int argc, char **argv) { PGconn *conn =3D PQconnectdb(argc > 1 ? argv[1] : "dbname=3Dpostgres"); if (PQstatus(conn) !=3D CONNECTION_OK) { fprintf(stderr, "%s", PQerrorMessage(conn)); PQfinish(conn); return 1; } printf("libpq=3D%d, PostgreSQL=3D%d\n", PQlibVersion(), PQserverVersion(conn)); /* Obtain both binary values from PostgreSQL, without constructing either. */ PGresult *values =3D PQexecParams( conn, "SELECT ''::tsquery, 'foo'::tsquery", 0, NULL, NULL, NULL, NULL, 1); require_row(values); const Oid types[] =3D {PQftype(values, 0)}; const char *params[] =3D {PQgetvalue(values, 0, 1)}; int lengths[] =3D {PQgetlength(values, 0, 1)}; int formats[] =3D {1}; PGresult *result =3D PQexecParams(conn, "SELECT $1", 1, types, params, lengths, formats, 0); require_row(result); if (PQgetisnull(result, 0, 0) || strcmp(PQgetvalue(result, 0, 0), "'foo'") !=3D 0) return 1; printf("Binary non-empty tsquery roundtrip: %s\n", PQgetvalue(result, 0, 0)); PQclear(result); params[0] =3D ""; lengths[0] =3D 0; formats[0] =3D 0; result =3D PQexecParams(conn, "SELECT $1", 1, types, params, lengths, formats, 0); require_row(result); if (PQgetisnull(result, 0, 0) || PQgetlength(result, 0, 0) !=3D 0) return 1; puts("Text empty tsquery roundtrip: OK"); PQclear(result); params[0] =3D PQgetvalue(values, 0, 0); lengths[0] =3D PQgetlength(values, 0, 0); formats[0] =3D 1; printf("Server-produced empty tsquery: type=3D%u, format=3D%d, length= =3D%d, hex=3D", types[0], PQfformat(values, 0), lengths[0]); for (int i =3D 0; i < lengths[0]; i++) printf("%02x", (unsigned char)params[0][i]); putchar('\n'); /* Send the server's bytes back unchanged, with the server's type OID. */ result =3D PQexecParams(conn, "SELECT $1", 1, types, params, lengths, formats, 0); const char *state =3D PQresultErrorField(result, PG_DIAG_SQLSTATE); const char *message =3D PQresultErrorField(result, PG_DIAG_MESSAGE_PRIMARY); const char *routine =3D PQresultErrorField(result, PG_DIAG_SOURCE_FUNCTION); int reproduced =3D PQresultStatus(result) =3D=3D PGRES_FATAL_ERROR && state && strcmp(state, "XX000") =3D=3D 0 && message && strcmp(message, "malformed tsquery: operand not found") =3D=3D 0 && routine && strcmp(routine, "findoprnd_recurse") =3D=3D 0; if (reproduced) printf("REPRODUCED: %s: %s (%s)\n", state, message, routine); else fprintf(stderr, "Expected server error was not reproduced: %s\n", PQresultErrorMessage(result)); PQclear(result); PQclear(values); PQfinish(conn); return reproduced ? 0 : 1; }