From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Daniel Verite <daniel@manitou-mail.org>
Cc: Robert Schreiber <bobschreiber@charter.net>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: PostgreSQL 9.3.5 substring(text from pattern for escape) bug
Date: Sun, 12 May 2019 04:19:23 +0100
Message-ID: <87mujsgz14.fsf@news-spur.riddles.org.uk> (raw)
In-Reply-To: <32565.1557590361@sss.pgh.pa.us>
References: <785708a0-a64c-42ee-9173-f596c1fc92ec@manitou-mail.org>
<32565.1557590361@sss.pgh.pa.us>
>>>>> "Tom" == Tom Lane <tgl@sss.pgh.pa.us> writes:
>>> What appears to be happening is that the _Q? on the tail_ is being
>>> matched, but _the Q is also being included in the collected data.__
>> You seem to expect that % must be non-greedy and let the final Q?
>> match 1 Q instead of 0, but there doesn't appear to be anything in
>> the doc that supports this interpretation. In fact, it mentions that
>> "%" is comparable to ".*" in POSIX regular expressions, and the
>> latter _is_ greedy.
Tom> Right. You could get the behavior you want using a non-greedy
Tom> quantifier, but you'd have to use the POSIX regexp functions, not
Tom> substring().
I looked up the spec on this point. As far as I can see, we're not
following it, but neither does the spec do what the OP wanted; in fact
the result should have included the _leading_ Q as well as the trailing
one.
The relevant part of SQL2016 seems to be this:
6.32 <string value function>
General Rules
6) If <regular expression substring function> is specified, then:
[...rules that split the pattern into 'R1#"R2#"R3' omitted...]
h) Otherwise, the result S of the <regular expression substring
function> is computed as follows:
i) Let S1 be the shortest initial substring of C such that there is
a substring S23 of C such that the value of the following <search
condition> is True:
'C' = 'S1' || 'S23' AND
'S1' SIMILAR TO 'R1' ESCAPE 'E' AND
'S23' SIMILAR TO '(R2R3)' ESCAPE 'E'
ii) Let S3 be the shortest final substring of S23 such that there is
a substring S2 of S23 such that the value of the following
<search condition> is True:
'S23' = 'S2' || 'S3' AND
'S2' SIMILAR TO 'R2' ESCAPE 'E' AND
'S3' SIMILAR TO 'R3' ESCAPE 'E'
iii) The result of the <regular expression substring function> is S2.
--
Andrew (irc:RhodiumToad)
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-bugs@postgresql.org
Cc: andrew@tao11.riddles.org.uk, tgl@sss.pgh.pa.us, daniel@manitou-mail.org, bobschreiber@charter.net
Subject: Re: PostgreSQL 9.3.5 substring(text from pattern for escape) bug
In-Reply-To: <87mujsgz14.fsf@news-spur.riddles.org.uk>
References: <785708a0-a64c-42ee-9173-f596c1fc92ec@manitou-mail.org> <32565.1557590361@sss.pgh.pa.us> <87mujsgz14.fsf@news-spur.riddles.org.uk>
* 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