From: James Olin Oden <joden@Lee.k12.nc.us>
To: Dan Delaney <dionysos@dionysia.org>
Cc: PostgreSQL SQL Discussion <pgsql-sql@postgresql.org>
Subject: Re: [SQL] Finding strings inside a field...
Date: Mon, 29 Jun 1998 18:10:50 -0400
Message-ID: <81Jun28.170305edt.35713@gateway.lee.k12.nc.us> (raw)
References: <Pine.BSF.3.96.980629172405.6263I-100000@dionysia.org>
> 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
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: joden@Lee.k12.nc.us, dionysos@dionysia.org
Subject: Re: [SQL] Finding strings inside a field...
In-Reply-To: <81Jun28.170305edt.35713@gateway.lee.k12.nc.us>
References: <Pine.BSF.3.96.980629172405.6263I-100000@dionysia.org> <81Jun28.170305edt.35713@gateway.lee.k12.nc.us>
* 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