From: Tom Lane <tgl@sss.pgh.pa.us>
To: kehan5800@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #19750: tsquery output omits parentheses, so the text reparses to a different value
Date: Mon, 05 Oct 2026 14:24:35 -0400
Message-ID: <1090121.1791224675@sss.pgh.pa.us> (raw)
In-Reply-To: <19750-d4e6f6e6e93000ba@postgresql.org>
References: <19750-d4e6f6e6e93000ba@postgresql.org>
PG Bug reporting form <noreply@postgresql.org> writes:
> tsquery's output function, infix() in src/backend/utils/adt/tsquery.c,
> parenthesises a binary operator's operand only when the operand's operator
> has lower priority than the parent (or, for <->, when it is the right
> operand). When the same operator, & or |, is nested on the right, no
> parentheses are written. The parser is left-associative, so that text
> reads back as a different tree, and tsquery equality compares trees:
On the whole I think this is intentional behavior, not a bug. The
only cases that don't "round trip" according to your definition are
"a & (b & c)" and "a | (b | c)", which are semantically equivalent
to the left-associative cases, so it seems like a legitimate
simplification to leave out the parens. The reason I think it was
intentional is that the code is actually more complex than it
would have to be otherwise: it treats OP_PHRASE differently from
the other binary operators, because for that the associativity
does matter.
regards, tom lane
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, kehan5800@gmail.com
Subject: Re: BUG #19750: tsquery output omits parentheses, so the text reparses to a different value
In-Reply-To: <1090121.1791224675@sss.pgh.pa.us>
References: <19750-d4e6f6e6e93000ba@postgresql.org> <1090121.1791224675@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