Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iIYb9-0004mD-9H for pgsql-general@arkaria.postgresql.org; Thu, 10 Oct 2019 13:35:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iIYb6-0002if-Hz for pgsql-general@arkaria.postgresql.org; Thu, 10 Oct 2019 13:35:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iIYb6-0002i8-7a for pgsql-general@lists.postgresql.org; Thu, 10 Oct 2019 13:35:16 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iIYb3-0000OI-73 for pgsql-general@lists.postgresql.org; Thu, 10 Oct 2019 13:35:15 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x9ADZ6T0021227; Thu, 10 Oct 2019 09:35:06 -0400 From: Tom Lane To: Alastair McKinley cc: "pgsql-general@lists.postgresql.org" , teodor@sigaev.ru Subject: Re: websearch_to_tsquery() and apostrophe inside double quotes In-reply-to: References: Comments: In-reply-to Alastair McKinley message dated "Thu, 10 Oct 2019 11:42:20 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <21224.1570714506.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 10 Oct 2019 09:35:06 -0400 Message-ID: <21225.1570714506@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Alastair McKinley writes: > I am a little confused about what us being generated by websearch_to_tsq= uery() in the case of an apostrophe inside double quotes. > ... > select websearch_to_tsquery('"peter o''toole"'); > websearch_to_tsquery > ------------------------------ > 'peter' <-> ( 'o' & 'tool' ) > (1 row) > I am not quite sure what text this will actually match? I believe it's impossible for that to match anything :-(. It would require 'o' and 'tool' to match the same lexeme (one immediately after a 'peter') which of course is impossible. The underlying tsvector type seems to treat the apostrophe the same as whitespace; it separates 'o' and 'toole' into distinct words: # select to_tsvector('peter o''toole'); to_tsvector = -------------------------- 'o':2 'peter':1 'tool':3 (1 row) So it seems to me that this is a bug: websearch_to_tsquery should also treat "'" like whitespace. There's certainly not anything in its documentation that suggests it should treat "'" specially. If it didn't, you'd get # select websearch_to_tsquery('"peter o toole"'); websearch_to_tsquery = ---------------------------- 'peter' <-> 'o' <-> 'tool' (1 row) which would match this tsvector. regards, tom lane