Re: Using union to avoid creating temp table

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruno Wolff III <bruno(at)wolff(dot)to>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Using union to avoid creating temp table
Date: 2002-07-01 17:17:30
Message-ID: 15083.1025543850@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Bruno Wolff III <bruno(at)wolff(dot)to> writes:
> 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 where add.id = role.id)

Might be worth writing "union all" not "union". This suppresses union's
check for duplicated rows, which you presumably don't need.

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jan Wieck 2002-07-01 18:13:34 Re: pg_restore cannot restore function
Previous Message Bruno Wolff III 2002-07-01 16:31:40 Using union to avoid creating temp table