pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruno Wolff III <bruno@wolff.to>
To: pgsql-sql@postgresql.org
Subject: Using union to avoid creating temp table
Date: Mon, 1 Jul 2002 11:31:40 -0500
Message-ID: <20020701163140.GA22475@wolff.to> (raw)

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 where add.id = role.id)

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





view thread (2+ messages)  latest in thread

Message-ID: <20020701163140.GA22475@wolff.to>
Permalink:  ../20020701163140.GA22475@wolff.to/
Also on:    postgresql.org/message-id/20020701163140.GA22475@wolff.to

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: bruno@wolff.to
  Subject: Re: Using union to avoid creating temp table
  In-Reply-To: <20020701163140.GA22475@wolff.to>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox