X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id B27F29FA31F for ; Thu, 29 Jun 2006 17:22:55 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 65927-01 for ; Thu, 29 Jun 2006 17:22:45 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 5D7809FA612 for ; Thu, 29 Jun 2006 17:22:45 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from webmail.getloaded.com (lb2.getloaded.com [8.7.97.12]) by svr4.postgresql.org (Postfix) with ESMTP id DA6565AF048 for ; Thu, 29 Jun 2006 20:00:44 +0000 (GMT) Received: from [192.168.1.9] (uslec-66-255-131-12.cust.uslec.net [66.255.131.12]) (authenticated bits=0) by webmail.getloaded.com (8.12.11.20060308/8.12.11) with ESMTP id k5TK0fmq029095 for ; Thu, 29 Jun 2006 16:00:42 -0400 Message-ID: <44A43172.3040202@getloaded.com> Date: Thu, 29 Jun 2006 16:00:50 -0400 From: Jason Farmer User-Agent: Thunderbird 1.5.0.4 (X11/20060615) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Using In Clause For a Large Text Matching Query Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/320 X-Sequence-Number: 25556 Hello all, my first post to the pgsql mailing list! There may be a completely better way to do this; if so please help point me in the right direction! What I'm trying to do is run a query to partially match 300+ text fields to a PG table of about 200,000 rows. The idea is to pull out a portion of text from the original text fields and do a partial text match on anything in my PG table containing that substring. I liked the idea of using a where IN(group) to do my comparisons, as in select col1 from table1 where col1 in ('text1','text2') however, this requires an exact string match. Is there any way to do a substring match inside of my IN group? Or can anyone think of a better way to do something like this? Heres an example of something of how I'd like this to work: Portion of 300 Original Text fields: "brown cat" "green dog" 2 rows of 200k+ Database table: "brown kitty" "green doggy" We can assume a certain portion of the text is included in the DB table, so I want to be able to do a substring match on "brown" and "green" and in this case return both "brown kitty", and "green doggy". However the problem is, if I run the query on each of my 300 rows to scan 200,000 rows in my DB is entirely too slow. So I was hoping to use the IN clause to create an IN group of about 300 items to scan the DB once. I hope this makes sense, but if anything sounds confusing please let me know, and I will be sure to clarify! Thanks for any help or direction anyone can provide!! - Jason Farmer