Subject | Re: [firebird-support] Strange SIMILAR TO result |
---|---|
Author | Gabor Boros |
Post date | 2018-05-07T11:57:11Z |
2018. 05. 07. 12:26 keltezéssel, Dimitry Sibiryakov sd@...
[firebird-support] írta:
SELECT '*' || CAST(''='' AS CHAR(5)) || '*',
CHARACTER_LENGTH(CAST(''='' AS CHAR(5))) FROM RDB$DATABASE
is
CONCATENATION CHAR_LENGTH
============= ============
*TRUE * 5
So I see what you say. But result of
SELECT CAST(''='' AS CHAR(5)) SIMILAR TO '[A-Z]{2}[0-9A-Z]{2,13}' FROM
RDB$DATABASE;
is
=======
<false>
So put the two case into one query
SELECT ''='' SIMILAR TO '[A-Z]{2}[0-9A-Z]{2,13}', CAST(''='' AS
CHAR(5)) SIMILAR TO '[A-Z]{2}[0-9A-Z]{2,13}' FROM RDB$DATABASE;
and the result is
======= =======
<true> <false>
And result of
SELECT 'TRUE ' SIMILAR TO '[A-Z]{2}[0-9A-Z]{2,13}' FROM RDB$DATABASE
is
=======
<false>
Gabor
[firebird-support] írta:
> 07.05.2018 12:19, Gabor Boros mlnglsts@... [firebird-support] wrote:Result of
>> A simple example: SELECT ''='' SIMILAR TO '[A-Z]{2}[0-9A-Z]{2,13}' FROM
>> RDB$DATABASE
>>
>> Why is the result true?
>
> Your expression is actually calculated as "CAST(''='' as CHAR(5)) SIMILAR TO
> '[A-Z]{2}[0-9A-Z]{2,13}'".
> (''='') is true and string representation of true is 'TRUE ' that matches your patters.
SELECT '*' || CAST(''='' AS CHAR(5)) || '*',
CHARACTER_LENGTH(CAST(''='' AS CHAR(5))) FROM RDB$DATABASE
is
CONCATENATION CHAR_LENGTH
============= ============
*TRUE * 5
So I see what you say. But result of
SELECT CAST(''='' AS CHAR(5)) SIMILAR TO '[A-Z]{2}[0-9A-Z]{2,13}' FROM
RDB$DATABASE;
is
=======
<false>
So put the two case into one query
SELECT ''='' SIMILAR TO '[A-Z]{2}[0-9A-Z]{2,13}', CAST(''='' AS
CHAR(5)) SIMILAR TO '[A-Z]{2}[0-9A-Z]{2,13}' FROM RDB$DATABASE;
and the result is
======= =======
<true> <false>
And result of
SELECT 'TRUE ' SIMILAR TO '[A-Z]{2}[0-9A-Z]{2,13}' FROM RDB$DATABASE
is
=======
<false>
Gabor