Re: SQL Regular Expression Question

From: missive(at)frontiernet(dot)net (Lee Harr)
To: pgsql-general(at)postgresql(dot)org
Subject: Re: SQL Regular Expression Question
Date: 2001-07-22 17:27:55
Message-ID: 9jf2eq$118u$1@node21.cwnet.roc.gblx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 20 Jul 2001 13:36:35 -0700, Blake <blake(at)shopwhatcom(dot)com> wrote:
> Wondering if someone could give me some guidance on this situation? I
> have a table column name "question" it contains a question, usally
> over 10 words. What I would like to do is give a user an option for
> searching the question column. I successfully, in PHP and Postgresql
> written a select statement to match a single word in the "question"
> column string: (its not very rodust)
>
> $query = pg_Exec($conn, "SELECT FROM faq WHERE question ~*
> 'OneKeyword'");
>
> How can I write a SQL Regualr Expression to match multiple "User
> Submitted" keywords and get a count on how many matched from the
> select statement??

Don't know if this helps or not, but how about:

SELECT * FROM faq WHERE question ~* 'OneKeyword' OR question ~* 'TwoKeyword'
or
SELECT * FROM faq WHERE question ~* 'OneKeyword' AND question ~* 'TwoKeyword'

or

SELECT count(*) FROM faq ...

Seems like with PHP you could build up the query string with ANDs or
ORs (depending on how you want it to work) and then submit the query.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mats Lofkvist 2001-07-22 18:36:43 Re: Planner estimates cost of 'like' a lot lower than '='??
Previous Message Tom Lane 2001-07-22 16:13:41 Re: Planner estimates cost of 'like' a lot lower than '='??