pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
inconsistent functionality with LIKE operator
3+ messages / 3 participants
[nested] [flat]

* inconsistent functionality with LIKE operator
@ 2001-03-29 08:25  Phuong Ma <pma@commandprompt.com>
  0 siblings, 2 replies; 3+ messages in thread

From: Phuong Ma @ 2001-03-29 08:25 UTC (permalink / raw)
  To: pgsql-general@postgresql.org; pgsql-sql

I'm using PostgreSQL version 7.1, and I'm having trouble with the LIKE
statement.  How would I find the value "a\bc"?  I tried using the
backslash to escape it: LIKE 'a\\b%';

If I specify: LIKE 'a\\bc', then it works, but if I wanted it to look
for consecetive characters after the c, using the %, then it returns
other values besides what I'm looking for.

I also have the same problem with percent (%).  I have a test string
with the value "ab%c", and I want to look for that using LIKE.  I tried:
LIKE 'ab\%c', LIKE 'ab%%', and LIKE 'ab\%_', but these statements not
only returned what I was looking for, but also other values:
"abc","ABC", and "Abc". 

Phuong



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: [SQL] inconsistent functionality with LIKE operator
@ 2001-03-29 16:43  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Phuong Ma <pma@commandprompt.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Tom Lane @ 2001-03-29 16:43 UTC (permalink / raw)
  To: Phuong Ma <pma@commandprompt.com>; +Cc: pgsql-general@postgresql.org; pgsql-sql

Phuong Ma <pma@commandprompt.com> writes:
> I'm using PostgreSQL version 7.1, and I'm having trouble with the LIKE
> statement.  How would I find the value "a\bc"?  I tried using the
> backslash to escape it: LIKE 'a\\b%';

I think you need four backslashes.  The string-literal parser eats one
level of backslashes, but you need the pattern that arrives at LIKE
to look like "a\\b%".

BTW, "PostgreSQL version 7.1" does not exist yet.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: inconsistent functionality with LIKE operator
@ 2001-03-29 17:07  will trillich <will@serensoft.com>
  parent: Phuong Ma <pma@commandprompt.com>
  1 sibling, 0 replies; 3+ messages in thread

From: will trillich @ 2001-03-29 17:07 UTC (permalink / raw)
  To: pgsql-general@postgresql.org

On Thu, Mar 29, 2001 at 08:25:30AM +0000, Phuong Ma wrote:
> I'm using PostgreSQL version 7.1, and I'm having trouble with the LIKE
> statement.  How would I find the value "a\bc"?  I tried using the
> backslash to escape it: LIKE 'a\\b%';
> 
> If I specify: LIKE 'a\\bc', then it works, but if I wanted it to look
> for consecetive characters after the c, using the %, then it returns
> other values besides what I'm looking for.
> 
> I also have the same problem with percent (%).  I have a test string
> with the value "ab%c", and I want to look for that using LIKE.  I tried:
> LIKE 'ab\%c', LIKE 'ab%%', and LIKE 'ab\%_', but these statements not
> only returned what I was looking for, but also other values:
> "abc","ABC", and "Abc". 

with LIKE, '%' means "anything" just as /.*/ does in a perl
regex; and '_' means "any character" just as /./ does in perl.

by default.

you can change the escape char, tho --

http://google.com/search?as_q=like+select+escape&as_sitesearch=postgresql.org


-- 
does a brain cell think?

will@serensoft.com
http://sourceforge.net/projects/newbiedoc -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2001-03-29 17:07 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-03-29 08:25 inconsistent functionality with LIKE operator Phuong Ma <pma@commandprompt.com>
2001-03-29 16:43 ` Tom Lane <tgl@sss.pgh.pa.us>
2001-03-29 17:07 ` will trillich <will@serensoft.com>

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