From: | "Daniel Verite" <daniel(at)manitou-mail(dot)org> |
---|---|
To: | "Robert Schreiber" <bobschreiber(at)charter(dot)net> |
Cc: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
Subject: | Re: PostgreSQL 9.3.5 substring(text from pattern for escape) bug |
Date: | 2019-05-11 11:18:23 |
Message-ID: | 785708a0-a64c-42ee-9173-f596c1fc92ec@manitou-mail.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
Robert Schreiber wrote:
> My understand of this is:
> Q? -- matches 0 or 1 occurrences of Q (the leading one, if present)
> #" -- starts data collection
> % -- matches any number of characters
> #" -- ends data collection
> Q? -- matches 0 or 1 occurrences of Q (the trialing one, if present)
>
> 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.__
The expression as a whole is being matched, otherwise this form of
substring() would return NULL, as told in
https://www.postgresql.org/docs/current/functions-matching.html :
"As with SIMILAR TO, the specified pattern must match the entire
data string, or else the function fails and returns null. "
Considering your example, where 'My Q NameQ' is the string and
'Q?#"%#"Q?' the regexp. The engine can either see the ending
'Q' as part of the % match, or as a match for the 'Q?' that
follows. Both cases are valid matches.
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.
Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2019-05-11 15:59:21 | Re: PostgreSQL 9.3.5 substring(text from pattern for escape) bug |
Previous Message | Robert Schreiber | 2019-05-11 04:02:57 | PostgreSQL 9.3.5 substring(text from pattern for escape) bug |