LIKE a set of pattern generated from a table - Mailing list pgsql-general

From Ivan Sergio Borgonovo
Subject LIKE a set of pattern generated from a table
Date
Msg-id 20100209180125.3ef2047a@dawn.webthatworks.it
Whole thread Raw
List pgsql-general
I've a column that contain something formed by concatenating fields
from another table

create table stuff(
 glued varchar(30),
  ...
);

insert into stuff select 'constA,' || field1 || ',' || field2 from
origin where ...;

insert into stuff select 'constB,' || field1 || ',' || field2 from
origin where ...;

I know this is terrible... but this is what I have, and I can't
change it.

Now what I'd like to do is selecting in stuff using a pattern as:

select * from stuff where glue like (
  select '%,' || field1 || ',' || field2 || '%'
    from origin
    where ...
);

But this isn't going to work.
Any other way other than specifying all the const one by one in a
union and then look for equality?

select * from stuff where glue in (
 select 'constA,' || field1 || ',' || field2 from
   origin where ...
 union
 select 'constB,' || field1 || ',' || field2 from
   origin where ...
);

--
Ivan Sergio Borgonovo
http://www.webthatworks.it


pgsql-general by date:

Previous
From: Boszormenyi Zoltan
Date:
Subject: Re: ERROR: could not load library "...": Exec format error
Next
From: Seb
Date:
Subject: SSL connection lost after long-lasting copy command