From: Tom Lane <tgl@sss.pgh.pa.us>
To: Johannes Graƫn <johannes@selfnet.de>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: tsvector string representation and parsing
Date: Wed, 23 Feb 2022 17:30:11 -0500
Message-ID: <1259438.1645655411@sss.pgh.pa.us> (raw)
In-Reply-To: <9e1f312a-92cf-e002-9bfd-728aa450ee09@selfnet.de>
References: <9e1f312a-92cf-e002-9bfd-728aa450ee09@selfnet.de>
=?UTF-8?Q?Johannes_Gra=c3=abn?= <johannes@selfnet.de> 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
=# 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 them with quotes
See also the next bit about having to double quotes and backslashes
within those quotes. So what you'd actually need is
=# 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, johannes@selfnet.de
Subject: Re: tsvector string representation and parsing
In-Reply-To: <1259438.1645655411@sss.pgh.pa.us>
References: <9e1f312a-92cf-e002-9bfd-728aa450ee09@selfnet.de> <1259438.1645655411@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox