Re: [SQL] Finding strings inside a field... - Mailing list pgsql-sql

From James Olin Oden
Subject Re: [SQL] Finding strings inside a field...
Date
Msg-id 81Jun28.170305edt.35713@gateway.lee.k12.nc.us
Whole thread Raw
In response to Finding strings inside a field...  (Dan Delaney <dionysos@dionysia.org>)
Responses Re: [SQL] Finding strings inside a field...  (Zsolt Varga <redax@agria.hu>)
List pgsql-sql
> Hello all.
>    Could any one tell me if the following is possible using
> PostgreSQL?
>
> I want to be able do a SELECT and search for a string INSIDE OF a
> field. So, say I want to get all record in testtable which contain
> the word "foobar" inside the "description" attribute. The following
> will only get those records in which the "description" attribute
> contains ONLY the word "foobar":
>
> SELECT FROM testtable WHERE description='foobar';
>
> What do I need to do to get all the record that have "foobar"
> ANYWHERE within the "description" field?
>    Thanks a lot.
>  --Dan
>

The answer is to use the LIKE operator along with the wildcard character
'%' (why they did not use * I will never know).  Anyway, say you wanted to
find all streets that contained 'Zion' then you would write something like
(no pun intended):

   SELECT * FROM streets WHERE street LIKE '%Zion%';

And as long as you have your handy dandy Hebrew translator, Zion would be
come Tziyon...just kidding, you would get all the streets that contain
'Zion' in there name.

Hope this helps...james



pgsql-sql by date:

Previous
From: CJB
Date:
Subject: Re: [SQL] gmake not found
Next
From: Brook Milligan
Date:
Subject: IN and subselects