Re: BUG #19750: tsquery output omits parentheses, so the text reparses to a different value - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #19750: tsquery output omits parentheses, so the text reparses to a different value
Date
Msg-id 1090121.1791224675@sss.pgh.pa.us
Whole thread
In response to BUG #19750: tsquery output omits parentheses, so the text reparses to a different value  (PG Bug reporting form <noreply@postgresql.org>)
List pgsql-bugs
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



pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #19742: `INTERSECT` under a `UNION ALL` with an empty arm fails with "could not find pathkey item t"
Next
From: shihao zhong
Date:
Subject: Re: BUG #17545: Incorrect selectivity for IS NOT DISTINCT FROM and NULLs