pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: brianb-pgsql@edsamail.com
To: pgsql-sql@postgresql.org
Subject: Search for underscore w/ LIKE
Date: Fri, 07 Jul 2000 09:09:24 GMT
Message-ID: <20000707090925.3041.qmail@mail01.edsamail.com.ph> (raw)


How do I use LIKE to search for strings with an underscore? The
documentation (well, Bruce's book) says to use 2 underscores (__) but it
doesn't work. For example:

create table liketest (
    somestr varchar(50)
);

insert into liketest values ('foo_bar');
insert into liketest values ('foobar');
insert into liketest values ('snackbar');
insert into liketest values ('crow_bar');

-- I want to select strings with "_bar"
select * from liketest where somestr like '%_bar';
 somestr  
----------
 foo_bar
 foobar
 snackbar
 crow_bar
(4 rows)

-- Using double underscore doesn't work either
select * from liketest where somestr like '%__bar';
 somestr  
----------
 foo_bar
 foobar
 snackbar
 crow_bar
(4 rows)

-- Escaping w/ backslash doesn't work 
select * from liketest where somestr like '%\_bar';
 somestr  
----------
 foo_bar
 foobar
 snackbar
 crow_bar
(4 rows)

Brian
--
Brian Baquiran <brianb@edsamail.com>
http://www.baquiran.com/ AIM: bbaquiran 
Work: (632)7182222       Home: (632)9227123



view thread (5+ messages)  latest in thread

Message-ID: <20000707090925.3041.qmail@mail01.edsamail.com.ph>
Permalink:  ../20000707090925.3041.qmail@mail01.edsamail.com.ph/
Also on:    postgresql.org/message-id/20000707090925.3041.qmail@mail01.edsamail.com.ph

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: brianb-pgsql@edsamail.com
  Subject: Re: Search for underscore w/ LIKE
  In-Reply-To: <20000707090925.3041.qmail@mail01.edsamail.com.ph>
  References: <20000707090925.3041.qmail@mail01.edsamail.com.ph>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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