pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Artz <mlartz@gmail.com>
To: Jim C. Nasby <jnasby@pervasive.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Bulk loading/merging
Date: Thu, 1 Jun 2006 14:04:46 -0400
Message-ID: <e9c163070606011104w1d0cf7a6jca8cf5b36f2d8de3@mail.gmail.com> (raw)
In-Reply-To: <20060531010922.GC59464@pervasive.com>
References: <ce4072df0605261148g4ec22267gc54b6b445e47c855@mail.gmail.com>
	<20060531010922.GC59464@pervasive.com>

On 5/30/06, Jim C. Nasby <jnasby@pervasive.com> wrote:

> Your best bet is to do this as a single, bulk operation if possible.
> That way you can simply do an UPDATE ... WHERE EXISTS followed by an
> INSERT ... SELECT ... WHERE NOT EXISTS.



 hmm, I don't quite understand what you are saying and I think my
basic misunderstanding is how to use the UPDATE ... WHERE EXISTS to merge
data in bulk.  Assuming that I bulk COPYed the data into a temporary
table, I'd need to issue an UPDATE for each row in the newly created table,
right?

For example, for a slightly different key,count schema:

CREATE TABLE kc (key integer, count integer);

and wanting to merge the following data by just updating the count for a
given key to the equivalent of OLD.count + NEW.count:

1,10
2,15
3,45
1,30

How would I go about using UPDATE ... WHERE EXISTS to update the "master" kc
table from a (temporary) table loaded with the above data?

view thread (6+ messages)  latest in thread

Message-ID: <e9c163070606011104w1d0cf7a6jca8cf5b36f2d8de3@mail.gmail.com>
Permalink:  ../e9c163070606011104w1d0cf7a6jca8cf5b36f2d8de3@mail.gmail.com/
Also on:    postgresql.org/message-id/e9c163070606011104w1d0cf7a6jca8cf5b36f2d8de3@mail.gmail.com

 · 

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-performance@postgresql.org
  Cc: mlartz@gmail.com, jnasby@pervasive.com
  Subject: Re: Bulk loading/merging
  In-Reply-To: <e9c163070606011104w1d0cf7a6jca8cf5b36f2d8de3@mail.gmail.com>

* 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