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 1xDnMf-00000000iRY-2HlY for pgsql-bugs@arkaria.postgresql.org; Mon, 05 Oct 2026 18:24:41 +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 1xDnMd-0000000CK2q-2e99 for pgsql-bugs@arkaria.postgresql.org; Mon, 05 Oct 2026 18:24:39 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xDnMd-0000000CK2h-1abd for pgsql-bugs@lists.postgresql.org; Mon, 05 Oct 2026 18:24:39 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xDnMa-00000000WGt-3Ul2 for pgsql-bugs@lists.postgresql.org; Mon, 05 Oct 2026 18:24:38 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 695IOZtq1090122; Mon, 5 Oct 2026 14:24:35 -0400 From: Tom Lane 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 In-reply-to: <19750-d4e6f6e6e93000ba@postgresql.org> References: <19750-d4e6f6e6e93000ba@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Sun, 04 Oct 2026 05:33:50 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1090120.1791224675.1@sss.pgh.pa.us> Date: Mon, 05 Oct 2026 14:24:35 -0400 Message-ID: <1090121.1791224675@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form 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