Re: BUG #4044: Incorrect RegExp substring Output

From: "Rui Martins" <Rui(dot)Martins(at)PDMFC(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #4044: Incorrect RegExp substring Output
Date: 2008-03-20 11:57:14
Message-ID: 2021.B1UHWUVdEF8=.1206014234.squirrel@www.pdmfc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

> "Rui Martins" <Rui(dot)Martins(at)PDMFC(dot)com> writes:
>> Even though this can me though as argumentative, think about this
>> expression:
>
>> (something)?
>
>> Will "match" with an empty string in the context of a full expression,
>> and
>> will return an EMPTY String. So by analogy, I would expect it, to return
>> the same as a sub-expression when it actually has a "match" even if with
>> an empty sub-string.
>
> Uh, no, it *won't* match if there is not "something" in the string.
>
> The behavior you are looking for is properly obtained this way:
>
> ((something)?)
>
> This will return either "something" or an empty string (assuming
> we have a globally successful match). The point is there's a difference
> between what X matches (or doesn't) and what X? matches.
>
> regards, tom lane

OK, what I'm trying to explain is maybe a difference of assumptions:

SELECT '' ~ '^(something)?$'

NOW: True
ME: True
YOU: True

SELECT SUBSTRING( '', '^(something)?$' )

NOW: '' => EMPTY String (OK, by pure luck. It's returning FULL match)
ME: '' => EMPTY String
YOU: NULL

SELECT 'TEST' ~ '^TEST(something)?$'

NOW: True
ME: True
YOU: True

SELECT SUBSTRING( 'TEST', '^TEST(something)?$' )

NOW: 'TEST' => WRONG !!! (It's returning FULL Match)
ME: '' => EMPTY String
YOU: NULL

My reasoning is:
Why would the exact same sub-expression, return different results when
either preceded or followed by something.
In my opinion, the same sub-expression should always return the same
result if the same conditions are met (in the sub-expression context).

Hope this time it's clear.

Best Regards
Rui Martins

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Alvaro Herrera 2008-03-20 12:41:17 Re: Problem identifying constraints which should not be inherited
Previous Message Heikki Linnakangas 2008-03-20 11:18:44 Re: 8.3 can't convert cyrillic text from 'iso-8859-5' to other cyrillic 8-bit encoding