Lists: | pgsql-sql |
---|
From: | Jesper Krogh <jesper(at)krogh(dot)cc> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | = or LIKE ? |
Date: | 2009-02-15 17:57:59 |
Message-ID: | 499857A7.4000201@krogh.cc |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-sql |
Hi.
Can anyone explain me this behavior?
testdb=# select E'\\' = E'\\';
?column?
----------
t
(1 row)
testdb=# select E'\\' like E'\\';
?column?
----------
f
(1 row)
Shouldnt the like operator do the same as the = if there occours no
wildcards and stuff in the string?
--
Jesper
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Jesper Krogh <jesper(at)krogh(dot)cc> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: = or LIKE ? |
Date: | 2009-02-15 18:42:40 |
Message-ID: | 23452.1234723360@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-sql |
Jesper Krogh <jesper(at)krogh(dot)cc> writes:
> Shouldnt the like operator do the same as the = if there occours no
> wildcards and stuff in the string?
If there are also no escape characters, then yeah.
FWIW, 8.4 will complain about this case:
regression=# select E'\\' like E'\\';
ERROR: LIKE pattern must not end with escape character
regards, tom lane
From: | Jesper Krogh <jesper(at)krogh(dot)cc> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: = or LIKE ? |
Date: | 2009-02-15 19:20:18 |
Message-ID: | 49986AF2.4010206@krogh.cc |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-sql |
Tom Lane wrote:
> Jesper Krogh <jesper(at)krogh(dot)cc> writes:
>> Shouldnt the like operator do the same as the = if there occours no
>> wildcards and stuff in the string?
>
> If there are also no escape characters, then yeah.
>
> FWIW, 8.4 will complain about this case:
>
> regression=# select E'\\' like E'\\';
> ERROR: LIKE pattern must not end with escape character
So I cannot rely on the like operator to behave correct if I'd like to
compare strings with backslashes (e.g. filepaths from MS Windows
filesystems)?
I actually get the same if it doesnt end with the slashes:
testdb=# select E'\\t' like E'\\t';
?column?
----------
f
(1 row)
testdb=# select E'\\t' = E'\\t';
?column?
----------
t
(1 row)
--
Jesper
From: | Jesper Krogh <jesper(at)krogh(dot)cc> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: = or LIKE ? |
Date: | 2009-02-15 19:27:03 |
Message-ID: | 49986C87.4010307@krogh.cc |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-sql |
Jesper Krogh wrote:
> Tom Lane wrote:
>> Jesper Krogh <jesper(at)krogh(dot)cc> writes:
>>> Shouldnt the like operator do the same as the = if there occours no
>>> wildcards and stuff in the string?
>>
>> If there are also no escape characters, then yeah.
>>
>> FWIW, 8.4 will complain about this case:
>>
>> regression=# select E'\\' like E'\\';
>> ERROR: LIKE pattern must not end with escape character
>
> So I cannot rely on the like operator to behave correct if I'd like to
> compare strings with backslashes (e.g. filepaths from MS Windows
> filesystems)?
>
> I actually get the same if it doesnt end with the slashes:
> testdb=# select E'\\t' like E'\\t';
> ?column?
> ----------
> f
> (1 row)
>
> testdb=# select E'\\t' = E'\\t';
> ?column?
> ----------
> t
> (1 row)
Ok. The pattern has to be "double escaped"..
testdb=# select E'\\t' like E'\\\\t';
?column?
----------
t
(1 row)
(for the archives a ref to the documentations i didnt get by the read
through)
http://www.postgresql.org/docs/8.2/static/functions-matching.html#FUNCTIONS-LIKE
--
Jesper
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Jesper Krogh <jesper(at)krogh(dot)cc> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: = or LIKE ? |
Date: | 2009-02-15 19:34:58 |
Message-ID: | 24996.1234726498@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-sql |
Jesper Krogh <jesper(at)krogh(dot)cc> writes:
> Ok. The pattern has to be "double escaped"..
Or specify a different escape character.
regards, tom lane
From: | Craig Ringer <craig(at)postnewspapers(dot)com(dot)au> |
---|---|
To: | Jesper Krogh <jesper(at)krogh(dot)cc> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: = or LIKE ? |
Date: | 2009-02-16 04:40:30 |
Message-ID: | 4998EE3E.6050404@postnewspapers.com.au |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-sql |
Jesper Krogh wrote:
> So I cannot rely on the like operator to behave correct if I'd like to
> compare strings with backslashes (e.g. filepaths from MS Windows
> filesystems)?
test=# SELECT E'\\' LIKE E'\\' ESCAPE '';
?column?
----------
t
(1 row)
--
Craig Ringer