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