selecting recs based on a tmp tbl vals that are wildcarded ?

From: "Gauthier, Dave" <dave(dot)gauthier(at)intel(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: selecting recs based on a tmp tbl vals that are wildcarded ?
Date: 2009-01-08 14:48:05
Message-ID: 482E80323A35A54498B8B70FF2B8798003E5AC7099@azsmsx504.amr.corp.intel.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have a temp table containg wildcarded strings and I want to select values froma different table using "like" against all those wildcarded values. Here's the example...

create temporary table match_these (val varchar(32));
insert into match_these (val) values ('jo%');
insert into match_these (val) values ('%denn_');
insert into match_these (val) values ('alt%');

create table footable (name varchar(32));
(insert a bunch of records)

Now...

select * from footable where name in (select val from match_these)

... won't work because "in" implies equality. I want something like...

select * from footable where name like (select val from match_these)

... but that doesn't work because the subquery returns more than one row :-(

Any elegant sql solutions out there before I brute-force a solution ?

Thanks in Advance !

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2009-01-08 15:03:01 Re: selecting recs based on a tmp tbl vals that are wildcarded ?
Previous Message Scott Marlowe 2009-01-08 14:48:04 Re: RCA for MemoryContextAlloc: invalid request size(Known Issue)