X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 522109FA040 for ; Thu, 1 Jun 2006 15:04:55 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 42078-07 for ; Thu, 1 Jun 2006 15:04:49 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from wx-out-0102.google.com (wx-out-0102.google.com [66.249.82.195]) by postgresql.org (Postfix) with ESMTP id 5FC4D9FA5C8 for ; Thu, 1 Jun 2006 15:04:47 -0300 (ADT) Received: by wx-out-0102.google.com with SMTP id h30so257827wxd for ; Thu, 01 Jun 2006 11:04:46 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=ED04lpUyovbvjEDA3d8Mz0HWpvA9DmyBrU4S8wEnaBRPylSzm5wwl2t1Dvzz0vDm+y+6/aXMNnvPbzs6QhXxafTMRg2PTnFVX+g+uFMYotMkkexBFTeGJO+qyRR2K4z+b1FwaejEXOu9kh4kEHl2sb6xd2m+QWGcuGftRO/YcCQ= Received: by 10.70.40.12 with SMTP id n12mr1111034wxn; Thu, 01 Jun 2006 11:04:46 -0700 (PDT) Received: by 10.70.113.12 with HTTP; Thu, 1 Jun 2006 11:04:46 -0700 (PDT) Message-ID: Date: Thu, 1 Jun 2006 14:04:46 -0400 From: "Michael Artz" To: "Jim C. Nasby" Subject: Re: Bulk loading/merging Cc: pgsql-performance@postgresql.org In-Reply-To: <20060531010922.GC59464@pervasive.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_5871_19810709.1149185086675" References: <20060531010922.GC59464@pervasive.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/6 X-Sequence-Number: 19363 ------=_Part_5871_19810709.1149185086675 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 5/30/06, Jim C. Nasby 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? ------=_Part_5871_19810709.1149185086675 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline
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?
 
 
------=_Part_5871_19810709.1149185086675--