Discussion:
rows into columns
(too old to reply)
t***@gmail.com
2014-09-30 20:17:00 UTC
Permalink
We have a query with a huge lists of ID's in an IN list......such as SELECT * WHERE id IN(id1, id2, id3.....id1400) list.

Is there a way to change it so that the the big "IN" lists could be changed so that the "IN" list was populated into a temp table first and then joined to to the rest of the query.

i.e. In the query below, it would change to "select * from a into temp mytemp"

with a(mycol) as (values('a'),('b'),('c'))
select * from a

MYCOL
-----
a
b
c



thanks in advance.
armsiee
2014-10-03 15:11:45 UTC
Permalink
Post by t***@gmail.com
We have a query with a huge lists of ID's in an IN list......such as SELECT * WHERE id IN(id1, id2, id3.....id1400) list.
Is there a way to change it so that the the big "IN" lists could be changed so that the "IN" list was populated into a temp table first and then joined to to the rest of the query.
i.e. In the query below, it would change to "select * from a into temp mytemp"
with a(mycol) as (values('a'),('b'),('c'))
select * from a
MYCOL
-----
a
b
c
thanks in advance.
Use an external file?

create temp table tmp_ids (id integer) with no log;

load from "id_file" insert into tmp_ids;

select * from TABLE where id in (select id from tmp_ids);

Loading...