Received: from localhost (uranus.hub.org [200.46.204.60]) by postgresql.org (Postfix) with ESMTP id 26F109FB304 for ; Fri, 10 Nov 2006 12:01:23 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.60]) (amavisd-new, port 10024) with ESMTP id 90610-04-3 for ; Fri, 10 Nov 2006 12:01:19 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from myemma.com (db1.e2ma.net [66.179.147.163]) by postgresql.org (Postfix) with ESMTP id B8AA89FB314 for ; Fri, 10 Nov 2006 12:01:13 -0400 (AST) Received: from localhost (localhost.localdomain [127.0.0.1]) by myemma.com (Postfix) with ESMTP id 2B6E123CE6; Fri, 10 Nov 2006 10:01:12 -0600 (CST) Received: from myemma.com ([127.0.0.1]) by localhost (velma [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 00659-10; Fri, 10 Nov 2006 10:01:10 -0600 (CST) Received: from [10.0.23.59] (unknown [209.149.59.218]) by myemma.com (Postfix) with ESMTP id A0AAB23CD6; Fri, 10 Nov 2006 10:01:10 -0600 (CST) Message-ID: <4554A246.3010701@myemma.com> Date: Fri, 10 Nov 2006 10:01:10 -0600 From: Erik Jones User-Agent: Thunderbird 1.5.0.7 (Windows/20060909) MIME-Version: 1.0 To: Travis Whitton Cc: pgsql-sql@postgresql.org Subject: Re: Wildcard LIKE and Sub-select References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at myemma.com X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/113 X-Sequence-Number: 26765 Travis Whitton wrote: > Hi everybody, > I have two tables of the following structure: > > Table "keywords" > > column | type > --------------------- > id | integer > keyword | varchar(255) > > and > > Table "badwords" > > column | type > ---------------------- > badword | varchar(255) > > > I need to delete all the rows from the keywords table where badword > partially matches the keyword field. I know I can do an exact match > with a sub-select, but I'm not sure how to structure a wildcard match > / like clause with a sub-select. Also, is that the best way to do it, > or should I be looking into full-text? I have roughly 10 million > keywords and 1 million badwords. > > Thanks, > Travis > Hmm... Maybe (this is untested): DELETE FROM keywords USING badwords WHERE keyword ILIKE ANY (SELECT '%' || badword || '%' FROM badwords) -- erik jones software development emma(r)