Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nN09p-0006c4-Uj for pgsql-general@arkaria.postgresql.org; Wed, 23 Feb 2022 22:30:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nN09I-0006VM-Jz for pgsql-general@arkaria.postgresql.org; Wed, 23 Feb 2022 22:30:16 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nN09I-0006TP-9M for pgsql-general@lists.postgresql.org; Wed, 23 Feb 2022 22:30:16 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nN09F-0001Id-Jz for pgsql-general@lists.postgresql.org; Wed, 23 Feb 2022 22:30:15 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 21NMUBW91259439; Wed, 23 Feb 2022 17:30:12 -0500 From: Tom Lane To: =?UTF-8?Q?Johannes_Gra=c3=abn?= cc: pgsql-general@lists.postgresql.org Subject: Re: tsvector string representation and parsing In-reply-to: <9e1f312a-92cf-e002-9bfd-728aa450ee09@selfnet.de> References: <9e1f312a-92cf-e002-9bfd-728aa450ee09@selfnet.de> Comments: In-reply-to =?UTF-8?Q?Johannes_Gra=c3=abn?= message dated "Wed, 23 Feb 2022 22:15:48 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1259437.1645655411.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 23 Feb 2022 17:30:11 -0500 Message-ID: <1259438.1645655411@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk =3D?UTF-8?Q?Johannes_Gra=3Dc3=3Dabn?=3D writes: > This is a minimal example that goes wrong (but shouldn't IMHO: >> SELECT format('%L:1', '\:')::tsvector format(%L) is designed to produce a SQL literal, which does not have the same requirements as a tsvector element ... yeah, they're close, but not close enough. In this particular example, what you get is =3D# SELECT format('%L:1', '\:'); format = ---------- E'\\:':1 (1 row) because format() adds an E prefix for the avoidance of doubt about what to do with the backslashes. tsvector doesn't like that. I don't think we have any prefab function that does what you're looking for here, and TBH I'm not sure I see the point of it. Pretty much any tsvector you'd be dealing with in practice is going to have come from one of the to_tsvector family of functions, and those tend to drop punctuation. > My understanding is that everything inside = > single quotes is taken as a lexeme. From the documentation: >> To represent lexemes containing whitespace or punctuation, surround the= m with quotes See also the next bit about having to double quotes and backslashes within those quotes. So what you'd actually need is =3D# select $$'\\:':1$$::tsvector; tsvector = ---------- '\\:':1 (1 row) If you write just one backslash, it has the effect of quoting the next character, which in this case doesn't need quoting. regards, tom lane