pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedLIKE operator and string comparison
4+ messages / 2 participants
[nested] [flat]
* LIKE operator and string comparison
@ 2004-09-22 22:54 Wei Weng <wweng@kencast.com>
2004-09-22 23:09 ` Re: LIKE operator and string comparison Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 4+ messages in thread
From: Wei Weng @ 2004-09-22 22:54 UTC (permalink / raw)
To: pgsql-sql
I used the following SQL code to match '\foo\bar'
SELECT text FROM test WHERE text LIKE '\\\\foo\\\\%'
But if I choose to use string comparison, instead of 4 escape characters, I
only need 2.
SELECT text FROM test WHERE text = '\\foo\\bar'
Why is that?
I am using PostgreSQL 7.4, and the SQL code was entered through psql.
Thanks!
Wei
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: LIKE operator and string comparison
2004-09-22 22:54 LIKE operator and string comparison Wei Weng <wweng@kencast.com>
@ 2004-09-22 23:09 ` Tom Lane <tgl@sss.pgh.pa.us>
2004-09-22 23:19 ` Re: LIKE operator and string comparison Wei Weng <wweng@kencast.com>
0 siblings, 1 reply; 4+ messages in thread
From: Tom Lane @ 2004-09-22 23:09 UTC (permalink / raw)
To: Wei Weng <wweng@kencast.com>; +Cc: pgsql-sql
Wei Weng <wweng@kencast.com> writes:
> But if I choose to use string comparison, instead of 4 escape characters, I
> only need 2.
> Why is that?
Backslash is an escape character for LIKE.
regards, tom lane
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: LIKE operator and string comparison
2004-09-22 22:54 LIKE operator and string comparison Wei Weng <wweng@kencast.com>
2004-09-22 23:09 ` Re: LIKE operator and string comparison Tom Lane <tgl@sss.pgh.pa.us>
@ 2004-09-22 23:19 ` Wei Weng <wweng@kencast.com>
2004-09-22 23:20 ` Re: LIKE operator and string comparison Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 4+ messages in thread
From: Wei Weng @ 2004-09-22 23:19 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-sql
Tom Lane wrote:
> Wei Weng <wweng@kencast.com> writes:
>
>>But if I choose to use string comparison, instead of 4 escape characters, I
>>only need 2.
>
>
>>Why is that?
>
>
> Backslash is an escape character for LIKE.
>
> regards, tom lane
>
>
What about in regular strings? I do need to use backslash to escape the
other backslash in order to get the '\'. Why isn't that the case in LIKE
operation?
Thanks
Wei
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: LIKE operator and string comparison
2004-09-22 22:54 LIKE operator and string comparison Wei Weng <wweng@kencast.com>
2004-09-22 23:09 ` Re: LIKE operator and string comparison Tom Lane <tgl@sss.pgh.pa.us>
2004-09-22 23:19 ` Re: LIKE operator and string comparison Wei Weng <wweng@kencast.com>
@ 2004-09-22 23:20 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 4+ messages in thread
From: Tom Lane @ 2004-09-22 23:20 UTC (permalink / raw)
To: Wei Weng <wweng@kencast.com>; +Cc: pgsql-sql
Wei Weng <wweng@kencast.com> writes:
> What about in regular strings? I do need to use backslash to escape the
> other backslash in order to get the '\'. Why isn't that the case in LIKE
> operation?
It is. You write four backslashes in order to describe a string
constant value containing two backslashes. When the LIKE code sees
that, it interprets it as one quoted backslash.
See LIKE ... ESCAPE if you'd like to use a different escape character
in the LIKE pattern.
regards, tom lane
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2004-09-22 23:20 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-09-22 22:54 LIKE operator and string comparison Wei Weng <wweng@kencast.com>
2004-09-22 23:09 ` Tom Lane <tgl@sss.pgh.pa.us>
2004-09-22 23:19 ` Wei Weng <wweng@kencast.com>
2004-09-22 23:20 ` Tom Lane <tgl@sss.pgh.pa.us>
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