Обсуждение: Pattern Matchig

Поиск
Список
Период
Сортировка

Pattern Matchig

От
Tk421
Дата:
Hello everybody
   I'm trying to make a query in a table to find the records who 
contains a full word 'im looking for.
   Here is an example about i'm trying
   code      text   1            foobar   2            xxxx foobar   3            xxxx foobar yyyyy   4
foobarxxxx   5            foobars   6            foobar.   7            xxxx foobar.
 
   What i want is to find foobar (records 1, 2, 3 and 4) but no foobars 
(record 5). If i try
      SELECT code FROM table WHERE text LIKE '%foobar%'
   The result is 1, 2, 3, 4, 5, 6, 7.  But if I try
      SELECT code FROM table WHERE text LIKE '% foobar %'
   The result is only record number 3. How can i search the entire 
FOOBAR word? The result wanted must be all, excepting 5.
   Thank you very much.
   PD: Sorry about my english


Re: Pattern Matchig

От
Alvaro Herrera
Дата:
Tk421 escribió:

>    The result is only record number 3. How can i search the entire  
> FOOBAR word? The result wanted must be all, excepting 5.

Something like this:

select code from table where text ~ '[[:<:]]foobar[[:>:]]'

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support


Re: Pattern Matchig

От
Tk421
Дата:
Alvaro Herrera escribió: <blockquote cite="mid:20080408172409.GJ9062@alvh.no-ip.org" type="cite"><pre wrap="">Tk421
escribió:
 </pre><blockquote type="cite"><pre wrap="">   The result is only record number 3. How can i search the entire  
FOOBAR word? The result wanted must be all, excepting 5.   </pre></blockquote><pre wrap="">
Something like this:

select code from table where text ~ '[[:<:]]foobar[[:>:]]'
 </pre></blockquote> Thank you very much, it worked!<br /><br /> Gracias, Álvaro<br />