If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Upsert command

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-16-03, 14:55
asram asram is offline
Registered User
 
Join Date: Jul 2003
Posts: 34
Upsert command

Hi,

We are on AIX 4.3 with UDB version "DB2 v8.1.1.16".

I would like to know more details about the "upsert" command. What I heard about it is it will insert if the row doesn't exist. If the row exists it will update. I want to try this in our development. Correct me if I'm wrong. Is this neew in V8.x?
Reply With Quote
  #2 (permalink)  
Old 10-16-03, 15:57
Brett Kaiser Brett Kaiser is offline
Window Washer
 
Join Date: Nov 2002
Location: Jersey
Posts: 10,303
Re: Upsert command

Quote:
Originally posted by asram
Hi,

We are on AIX 4.3 with UDB version "DB2 v8.1.1.16".

I would like to know more details about the "upsert" command. What I heard about it is it will insert if the row doesn't exist. If the row exists it will update. I want to try this in our development. Correct me if I'm wrong. Is this neew in V8.x?
This is a joke...right?
__________________
Brett
8-)

It's a Great Day for America everybody!

dbforums Yak CorralRadio 'Rita
dbForums Member List
I'm Good Once as I ever was

The physical order of data in a database has no meaning.
Reply With Quote
  #3 (permalink)  
Old 10-16-03, 17:26
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Re: Upsert command

Actually, it is no joke. MERGE INTO (aka UPSERT) is a new feature that was introduced at version 8.1.2.

Asram will have to apply either fixpack 2 or 3 to get this new feature.

Andy


Quote:
Originally posted by Brett Kaiser
This is a joke...right?
Reply With Quote
  #4 (permalink)  
Old 10-16-03, 17:30
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
It also is a feature of the IMPORT command, but I assume that the IMPORT utility does the checking via code and does not use the MERGE INTO SQL syntax internally.
Reply With Quote
  #5 (permalink)  
Old 10-16-03, 20:18
chuzhoi chuzhoi is offline
Registered User
 
Join Date: Dec 2002
Posts: 134
Re: Upsert command

Prior 8.1 (starting from 7.1 fixpack 3) it was possible to use "upsert", "updel" and so on, for insert/update/delete in one UOW as compound statement.

Check the following article:
http://www-1.ibm.com/support/docview...id=swg21008451

Sample syntax :
BEGIN ATOMIC
FOR row AS
SELECT fact.pkf, stage.pks, stage.c1
FROM fact RIGHT OUTER JOIN stage
ON fact.pkf = stage.pks DO
IF row.pkf IS NULL THEN
INSERT INTO fact VALUES(row.pks, row.c1);
ELSE
UPDATE fact SET c1 = row.c1
WHERE fact.pkf = row.pkf;
END IF;
END FOR;
END
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On