Determining if "in a text set"

From: Richi Plana <richip(at)mozcom(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Determining if "in a text set"
Date: 1999-03-27 04:41:48
Message-ID: Pine.LNX.4.04.9903271223140.22809-100000@jaguar.mozcom.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

Hi,

I have a table/class with a text field which contains a single word
(possibly trailed by whitespaces). Given a phrase (a text literal composed
of words separated by one or more whitespaces), what's the best way to
SELECT those tuples with fields containing instances that match exactly
one of the words in the given string?

Example:

Table:
Tuple# ... FieldN
1 ... 'MON'
2 ... 'TUE'
3 ... 'THURS'
4 ... 'THU'
5 ... 'FRI'

Given phrase:
'MON TUE WED THURS'
Tuple 1 will match
Tuple 2 will match
Tuple 3 will match
Tuple 4 will NOT match
Tuple 5 will NOT match

Right now, I'm extracting (using strtok(), 8^P) each word from the given
phrase and using "SELECT * FROM {class} where FieldN LIKE '%{word}%'", but
it's terribly slow, relies on strtok() to parse words, and Tuple 4 above
will match.

L L Richi Plana 8^) ,-,-. ,-,-. ,-,-. ,-,-. ,-
LL LL Systems Administrator / / \ \ / / \ \ / / \ \ / / \ \ / /
LLLLL Mosaic Communications, Inc. \ \ / / \ \ / / \ \ / / \ \ / /
LLLLL mailto:richip(at)mozcom(dot)com `-'-' `-'-' `-'-' `-'-'
------------------------------------------------------------------------
P G P Key available at http://www2.mozcom.com/~richip/richip.asc
Tired of Spam? Join this CAUCE! http://www.cauce.org/

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Peter Davidse 1999-03-27 22:14:07 Postgres and Perl5 and apache
Previous Message John Steely 1999-03-27 04:34:13 Re: How do I "Insert" using a type member?

Browse pgsql-sql by date

  From Date Subject
Next Message Herouth Maoz 1999-03-28 15:48:20 Re: [SQL] Odd "problem", not sure if there is a solution ....
Previous Message Andrew Douglas 1999-03-26 21:42:18 newbie question about type conversions