SELECT woes

Lists: pgsql-novice
From: Jeffrey Melloy <jmelloy(at)visualdistortion(dot)org>
To: Kevin Waterson <kevin(at)oceania(dot)net>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: SELECT woes
Date: 2003-09-02 07:34:27
Message-ID: E1D6B11E-DD17-11D7-A0F4-000393C78AC0@visualdistortion.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

Yuck.

My suggestion would be to install the tsearch or tsearch2 module, and
modify the on-insert trigger to include the contents of all the fields
in your table. There are examples in the tsearch readme, but you can
set the trigger on multiple columns. Then that query would probably be
very fast and would turn into
select * from table where master_idx ## 'my|name|is|bill'
You can also do more powerful levels of grouping and boolean logic.
Jeff
On Tuesday, September 2, 2003, at 02:51 AM, Kevin Waterson wrote:

> I wish to SELECT * FROM testTable WHERE any field contains any word in
> the
> string "my name is bill"
> All I can come up with is this.
> SELECT * FROM testTable WHERE testfeild LIKE '%my%' OR testfield2 LIKE
> '%my%' OR testfeild LIKE '%name%' OR testfield2 LIKE '%name%' OR
> testfeild LIKE '%is%' OR testfield2 LIKE '%is%' OR testfeild LIKE
> '%bill%' OR testfield2 LIKE '%bill%'
>
> Is there a better/more efficient way?
>
> Kind regards
> Kevin
>
> --
> ______
> (_____ \
> _____) ) ____ ____ ____ ____
> | ____/ / _ ) / _ | / ___) / _ )
> | | ( (/ / ( ( | |( (___ ( (/ /
> |_| \____) \_||_| \____) \____)
> Kevin Waterson
> Port Macquarie, Australia
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly


From: Kevin Waterson <kevin(at)oceania(dot)net>
To: pgsql-novice(at)postgresql(dot)org
Subject: SELECT woes
Date: 2003-09-02 07:51:33
Message-ID: 20030902175133.199bdbc0.kevin@oceania.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

I wish to SELECT * FROM testTable WHERE any field contains any word in the
string "my name is bill"
All I can come up with is this.
SELECT * FROM testTable WHERE testfeild LIKE '%my%' OR testfield2 LIKE '%my%' OR testfeild LIKE '%name%' OR testfield2 LIKE '%name%' OR testfeild LIKE '%is%' OR testfield2 LIKE '%is%' OR testfeild LIKE '%bill%' OR testfield2 LIKE '%bill%'

Is there a better/more efficient way?

Kind regards
Kevin

--
______
(_____ \
_____) ) ____ ____ ____ ____
| ____/ / _ ) / _ | / ___) / _ )
| | ( (/ / ( ( | |( (___ ( (/ /
|_| \____) \_||_| \____) \____)
Kevin Waterson
Port Macquarie, Australia


From: Kevin Waterson <kevin(at)oceania(dot)net>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: SELECT woes
Date: 2003-09-02 09:58:29
Message-ID: 20030902195829.468bde2b.kevin@oceania.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

This one time, at band camp, Jeffrey Melloy <jmelloy(at)visualdistortion(dot)org> wrote:

> Yuck.
>
> My suggestion would be to install the tsearch or tsearch2 module, and
> modify the on-insert trigger to include the contents of all the fields
> in your table. There are examples in the tsearch readme, but you can
> set the trigger on multiple columns. Then that query would probably be
> very fast and would turn into
> select * from table where master_idx ## 'my|name|is|bill'
> You can also do more powerful levels of grouping and boolean logic.
> Jeff
> On Tuesday, September 2, 2003, at 02:51 AM, Kevin Waterson wrote:

Then it would not be compatible with other databases.

Kind regards
Kevin

--
______
(_____ \
_____) ) ____ ____ ____ ____
| ____/ / _ ) / _ | / ___) / _ )
| | ( (/ / ( ( | |( (___ ( (/ /
|_| \____) \_||_| \____) \____)
Kevin Waterson
Port Macquarie, Australia


From: Rasputin <rasputin(at)idoru(dot)mine(dot)nu>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: SELECT woes
Date: 2003-09-02 10:16:05
Message-ID: 20030902101605.GA23844@lb.tenfour
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

* Kevin Waterson <kevin(at)oceania(dot)net> [0952 09:52]:
> This one time, at band camp, Jeffrey Melloy <jmelloy(at)visualdistortion(dot)org> wrote:
>
> > Yuck.
> >
> > My suggestion would be to install the tsearch or tsearch2 module, and
> > modify the on-insert trigger to include the contents of all the fields
> > in your table. There are examples in the tsearch readme, but you can
> > set the trigger on multiple columns. Then that query would probably be
> > very fast and would turn into
> > select * from table where master_idx ## 'my|name|is|bill'
> > You can also do more powerful levels of grouping and boolean logic.
> > Jeff
> > On Tuesday, September 2, 2003, at 02:51 AM, Kevin Waterson wrote:
>
> Then it would not be compatible with other databases.

True,
but I don't think there is an standard SQL way of doing what you want.

The alternative would be to fidn all rows that contain 'bill'
and then have your application dump the ones that don't contain the other
words - that would be more portable but is really clanky, and
adds complexity to the client.

--
An idea is not responsible for the people who believe in it.
Rasputin :: Jack of All Trades - Master of Nuns


From: Jeffrey Melloy <jmelloy(at)visualdistortion(dot)org>
To: Kevin Waterson <kevin(at)oceania(dot)net>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: SELECT woes
Date: 2003-09-02 14:43:28
Message-ID: D0ED8E11-DD53-11D7-B01B-000393C78AC0@visualdistortion.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice


On Tuesday, September 2, 2003, at 04:58 AM, Kevin Waterson wrote:

> This one time, at band camp, Jeffrey Melloy
> <jmelloy(at)visualdistortion(dot)org> wrote:
>
>> Yuck.
>>
>> My suggestion would be to install the tsearch or tsearch2 module, and
>> modify the on-insert trigger to include the contents of all the fields
>> in your table. There are examples in the tsearch readme, but you can
>> set the trigger on multiple columns. Then that query would probably
>> be
>> very fast and would turn into
>> select * from table where master_idx ## 'my|name|is|bill'
>> You can also do more powerful levels of grouping and boolean logic.
>> Jeff
>> On Tuesday, September 2, 2003, at 02:51 AM, Kevin Waterson wrote:
>
> Then it would not be compatible with other databases.
>
You didn't list that as a constraint. :)
> Kind regards
> Kevin
>
>
> --
> ______
> (_____ \
> _____) ) ____ ____ ____ ____
> | ____/ / _ ) / _ | / ___) / _ )
> | | ( (/ / ( ( | |( (___ ( (/ /
> |_| \____) \_||_| \____) \____)
> Kevin Waterson
> Port Macquarie, Australia
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly