pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Erik Jones <erik@myemma.com>
To: Travis Whitton <tinymountain@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Wildcard LIKE and Sub-select
Date: Fri, 10 Nov 2006 10:01:10 -0600
Message-ID: <4554A246.3010701@myemma.com> (raw)
In-Reply-To: <cf9b4f3e0611100723r617301cen7f56902e288f1011@mail.gmail.com>
References: <cf9b4f3e0611100723r617301cen7f56902e288f1011@mail.gmail.com>

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 <erik@myemma.com>
software development
emma(r)




view thread (3+ messages)  latest in thread

Message-ID: <4554A246.3010701@myemma.com>
Permalink:  ../4554A246.3010701@myemma.com/
Also on:    postgresql.org/message-id/4554A246.3010701@myemma.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: erik@myemma.com, tinymountain@gmail.com
  Subject: Re: Wildcard LIKE and Sub-select
  In-Reply-To: <4554A246.3010701@myemma.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox