Using union to avoid creating temp table - Mailing list pgsql-sql

From Bruno Wolff III
Subject Using union to avoid creating temp table
Date
Msg-id 20020701163140.GA22475@wolff.to
Whole thread Raw
Responses Re: Using union to avoid creating temp table
List pgsql-sql
I don't know if this is a well known trick or not. I wanted to check a
list of values inputted to a script against some existing tables. I was
trying to think of alternatives to using a temp table and copy since
this would take two requests instead of one.

What I ended up doing is building the input values into sepearte
select statements unioned together. So if the input values were
'abc', 'def' and 'ghi', I would end up doing a select like:
select add.id from (select 'abc' union select 'def' union select 'ghi') add (id)where not exists (select from role
whereadd.id = role.id)
 

I don't know whether or not this is faster in general, but it probably is
under at least some circumstances.




pgsql-sql by date:

Previous
From: Roberto Mello
Date:
Subject: Re: pl/pgsql capabilities?
Next
From: "Simeone, Mario"
Date:
Subject: unsubscribe