pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Robert Schreiber <bobschreiber@charter.net>
To: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Daniel Verite <daniel@manitou-mail.org>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: PostgreSQL 9.3.5 substring(text from pattern for escape) bug
Date: Mon, 13 May 2019 05:36:30 -0400
Message-ID: <3db2d381-c94d-c6b8-10a8-7cf0ddda6c09@charter.net> (raw)
In-Reply-To: <87imuggwi4.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>
	<27602.1557633043@sss.pgh.pa.us>
	<87imuggwi4.fsf@news-spur.riddles.org.uk>

Just to be clear here. It seems to me that I am right in that the 
leading/trailing Q should NOT be returned...

 From Section 9.7.2 in the manual:

    The |substring| function with three parameters, |substring(/string/
    from /pattern/ for /escape-character/)|, provides extraction of a
    substring that matches an SQL regular expression pattern. As with
    SIMILAR TO, the specified pattern must match the entire data string,
    or else the function fails and returns null. To indicate the part of
    the pattern that should be returned on success, the pattern must
    contain two occurrences of the escape character followed by a double
    quote ("). The text matching the portion of the pattern between
    these markers is returned.


In my mind I see this:

QMy Q NAmeQ  is interpreted as Q/My Q Name/Q rather than Q/My Q Name Q//.

bob



On 5/12/2019 12:27 AM, Andrew Gierth wrote:
>>>>>> "Tom" == Tom Lane <tgl@sss.pgh.pa.us> writes:
>   > Andrew Gierth <andrew@tao11.riddles.org.uk> writes:
>   >> 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.
>
>   Tom> Huh, interesting. So we should be translating the initial
>   Tom> substring to a non-greedy pattern. I believe Spencer's engine can
>   Tom> handle that by sticking (?:...){1,1}? around it.
>
>   Tom> Come to think of it, we probably need to be putting (?:...) around
>   Tom> the trailing substring as well. I suspect what we're doing today
>   Tom> produces non-spec results if "|" appears in the trailing part.
>
> Digging into it more:
>
> SUBSTRING(x FROM 'expr' FOR 'escape') is from sql92/sql99 and is gone by
> sql2008, replaced by SUBSTRING(x SIMILAR 'expr' ESCAPE 'escape'). sql99
> defines the matching rule using different language, but with the same
> actual effect (requiring shortest matches for the leading and trailing
> strings).
>
> Your suggested fix doesn't seem to work. If the leading/trailing
> substrings do not have | or parens in then it seems to work to wrap them
> in (?:(?:)??...), thanks to the rule that the first quantified atom in a
> subexpression sets the whole subexpression's greediness, but handling |
> or parens correctly seems harder.
>
> Are there any other dbs that implement this feature that we can compare
> against?
>

view thread (12+ messages)  latest in thread

Message-ID: <3db2d381-c94d-c6b8-10a8-7cf0ddda6c09@charter.net>
Permalink:  ../3db2d381-c94d-c6b8-10a8-7cf0ddda6c09@charter.net/
Also on:    postgresql.org/message-id/3db2d381-c94d-c6b8-10a8-7cf0ddda6c09@charter.net

 · 

reply

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: bobschreiber@charter.net, andrew@tao11.riddles.org.uk, tgl@sss.pgh.pa.us, daniel@manitou-mail.org
  Subject: Re: PostgreSQL 9.3.5 substring(text from pattern for escape) bug
  In-Reply-To: <3db2d381-c94d-c6b8-10a8-7cf0ddda6c09@charter.net>
  References: <785708a0-a64c-42ee-9173-f596c1fc92ec@manitou-mail.org> <32565.1557590361@sss.pgh.pa.us> <87mujsgz14.fsf@news-spur.riddles.org.uk> <27602.1557633043@sss.pgh.pa.us> <87imuggwi4.fsf@news-spur.riddles.org.uk> <3db2d381-c94d-c6b8-10a8-7cf0ddda6c09@charter.net>

* 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