dbTalk Databases Forums  

upsert strategies?

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss upsert strategies? in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
mh@pixar.com
 
Posts: n/a

Default upsert strategies? - 10-26-2008 , 01:44 AM






So far, I've figured out 4 possible ways to perform upsert-like
functionality:

1. try insert, on exception update
2. try update, on exception insert
3. delete, then insert
4. merge with DUAL

It seems so far the nicest solution is #4.

Here's some questions:

- Do the other methods have any features which might recommend them?

- Are there any methods that might be portable to other databases?

- Are there any methods I might be overlooking?

Many TIA!
Mark

--
Mark Harrison
Pixar Animation Studios

Reply With Quote
  #2  
Old   
gym dot scuba dot kennedy at gmail
 
Posts: n/a

Default Re: upsert strategies? - 10-26-2008 , 03:10 AM







<mh (AT) pixar (DOT) com> wrote

Quote:
So far, I've figured out 4 possible ways to perform upsert-like
functionality:

1. try insert, on exception update
2. try update, on exception insert
3. delete, then insert
4. merge with DUAL

It seems so far the nicest solution is #4.

Here's some questions:

- Do the other methods have any features which might recommend them?

- Are there any methods that might be portable to other databases?

- Are there any methods I might be overlooking?

Many TIA!
Mark

--
Mark Harrison
Pixar Animation Studios
#2 won't work. You will update 0 rows which isn't an error.
#3 is terrible. You are generating a lot more redo etc. than you need to.
Just use the merge statement. I don't see what dual has to do with it. You
should be able to do it in one statement.
Jim




Reply With Quote
  #3  
Old   
gym dot scuba dot kennedy at gmail
 
Posts: n/a

Default Re: upsert strategies? - 10-26-2008 , 03:10 AM




<mh (AT) pixar (DOT) com> wrote

Quote:
So far, I've figured out 4 possible ways to perform upsert-like
functionality:

1. try insert, on exception update
2. try update, on exception insert
3. delete, then insert
4. merge with DUAL

It seems so far the nicest solution is #4.

Here's some questions:

- Do the other methods have any features which might recommend them?

- Are there any methods that might be portable to other databases?

- Are there any methods I might be overlooking?

Many TIA!
Mark

--
Mark Harrison
Pixar Animation Studios
#2 won't work. You will update 0 rows which isn't an error.
#3 is terrible. You are generating a lot more redo etc. than you need to.
Just use the merge statement. I don't see what dual has to do with it. You
should be able to do it in one statement.
Jim




Reply With Quote
  #4  
Old   
gym dot scuba dot kennedy at gmail
 
Posts: n/a

Default Re: upsert strategies? - 10-26-2008 , 03:10 AM




<mh (AT) pixar (DOT) com> wrote

Quote:
So far, I've figured out 4 possible ways to perform upsert-like
functionality:

1. try insert, on exception update
2. try update, on exception insert
3. delete, then insert
4. merge with DUAL

It seems so far the nicest solution is #4.

Here's some questions:

- Do the other methods have any features which might recommend them?

- Are there any methods that might be portable to other databases?

- Are there any methods I might be overlooking?

Many TIA!
Mark

--
Mark Harrison
Pixar Animation Studios
#2 won't work. You will update 0 rows which isn't an error.
#3 is terrible. You are generating a lot more redo etc. than you need to.
Just use the merge statement. I don't see what dual has to do with it. You
should be able to do it in one statement.
Jim




Reply With Quote
  #5  
Old   
gym dot scuba dot kennedy at gmail
 
Posts: n/a

Default Re: upsert strategies? - 10-26-2008 , 03:10 AM




<mh (AT) pixar (DOT) com> wrote

Quote:
So far, I've figured out 4 possible ways to perform upsert-like
functionality:

1. try insert, on exception update
2. try update, on exception insert
3. delete, then insert
4. merge with DUAL

It seems so far the nicest solution is #4.

Here's some questions:

- Do the other methods have any features which might recommend them?

- Are there any methods that might be portable to other databases?

- Are there any methods I might be overlooking?

Many TIA!
Mark

--
Mark Harrison
Pixar Animation Studios
#2 won't work. You will update 0 rows which isn't an error.
#3 is terrible. You are generating a lot more redo etc. than you need to.
Just use the merge statement. I don't see what dual has to do with it. You
should be able to do it in one statement.
Jim




Reply With Quote
  #6  
Old   
ddf
 
Posts: n/a

Default Re: upsert strategies? - 10-28-2008 , 01:19 PM



On Oct 26, 4:10*am, "gym dot scuba dot kennedy at gmail"
<kenned... (AT) verizon (DOT) net> wrote:
Quote:
m... (AT) pixar (DOT) com> wrote in message

news:JlUMk.3915$D32.1708 (AT) flpi146 (DOT) ffdc.sbc.com...



So far, I've figured out 4 possible ways to perform upsert-like
functionality:

1. try insert, on exception update
2. try update, on exception insert
3. delete, then insert
4. merge with DUAL

It seems so far the nicest solution is #4.

Here's some questions:

- Do the other methods have any features which might recommend them?

- Are there any methods that might be portable to other databases?

- Are there any methods I might be overlooking?

Many TIA!
Mark

--
Mark Harrison
Pixar Animation Studios

#2 won't work. *You will update 0 rows which isn't an error.
#3 is terrible. *You are generating a lot more redo etc. than you need to.
Just use the merge statement. *I don't see what dual has to do with it.*You
should be able to do it in one statement.
Jim- Hide quoted text -

- Show quoted text -
The issue here is to perform a MERGE using only one table, not two,
hence the use of DUAL. Out of all of the listed possibilities the
actual MERGE, using DUAL, is your best bet:

merge into employee e
using (select 20 as id from dual) i on (e.id = i.id)
when matched then
update
set salary = salary + 10000
when not matched then
insert
values('BLORPO',20,12000)
/

You'll not find anything useful in this regard that is portable; then,
why do you need it to be? You're better served by writing to the dbms
in use, not attempting to generate 'universal' code which likely won't
scale nor will it perform.


David Fitzjarrell


Reply With Quote
  #7  
Old   
ddf
 
Posts: n/a

Default Re: upsert strategies? - 10-28-2008 , 01:19 PM



On Oct 26, 4:10*am, "gym dot scuba dot kennedy at gmail"
<kenned... (AT) verizon (DOT) net> wrote:
Quote:
m... (AT) pixar (DOT) com> wrote in message

news:JlUMk.3915$D32.1708 (AT) flpi146 (DOT) ffdc.sbc.com...



So far, I've figured out 4 possible ways to perform upsert-like
functionality:

1. try insert, on exception update
2. try update, on exception insert
3. delete, then insert
4. merge with DUAL

It seems so far the nicest solution is #4.

Here's some questions:

- Do the other methods have any features which might recommend them?

- Are there any methods that might be portable to other databases?

- Are there any methods I might be overlooking?

Many TIA!
Mark

--
Mark Harrison
Pixar Animation Studios

#2 won't work. *You will update 0 rows which isn't an error.
#3 is terrible. *You are generating a lot more redo etc. than you need to.
Just use the merge statement. *I don't see what dual has to do with it.*You
should be able to do it in one statement.
Jim- Hide quoted text -

- Show quoted text -
The issue here is to perform a MERGE using only one table, not two,
hence the use of DUAL. Out of all of the listed possibilities the
actual MERGE, using DUAL, is your best bet:

merge into employee e
using (select 20 as id from dual) i on (e.id = i.id)
when matched then
update
set salary = salary + 10000
when not matched then
insert
values('BLORPO',20,12000)
/

You'll not find anything useful in this regard that is portable; then,
why do you need it to be? You're better served by writing to the dbms
in use, not attempting to generate 'universal' code which likely won't
scale nor will it perform.


David Fitzjarrell


Reply With Quote
  #8  
Old   
ddf
 
Posts: n/a

Default Re: upsert strategies? - 10-28-2008 , 01:19 PM



On Oct 26, 4:10*am, "gym dot scuba dot kennedy at gmail"
<kenned... (AT) verizon (DOT) net> wrote:
Quote:
m... (AT) pixar (DOT) com> wrote in message

news:JlUMk.3915$D32.1708 (AT) flpi146 (DOT) ffdc.sbc.com...



So far, I've figured out 4 possible ways to perform upsert-like
functionality:

1. try insert, on exception update
2. try update, on exception insert
3. delete, then insert
4. merge with DUAL

It seems so far the nicest solution is #4.

Here's some questions:

- Do the other methods have any features which might recommend them?

- Are there any methods that might be portable to other databases?

- Are there any methods I might be overlooking?

Many TIA!
Mark

--
Mark Harrison
Pixar Animation Studios

#2 won't work. *You will update 0 rows which isn't an error.
#3 is terrible. *You are generating a lot more redo etc. than you need to.
Just use the merge statement. *I don't see what dual has to do with it.*You
should be able to do it in one statement.
Jim- Hide quoted text -

- Show quoted text -
The issue here is to perform a MERGE using only one table, not two,
hence the use of DUAL. Out of all of the listed possibilities the
actual MERGE, using DUAL, is your best bet:

merge into employee e
using (select 20 as id from dual) i on (e.id = i.id)
when matched then
update
set salary = salary + 10000
when not matched then
insert
values('BLORPO',20,12000)
/

You'll not find anything useful in this regard that is portable; then,
why do you need it to be? You're better served by writing to the dbms
in use, not attempting to generate 'universal' code which likely won't
scale nor will it perform.


David Fitzjarrell


Reply With Quote
  #9  
Old   
ddf
 
Posts: n/a

Default Re: upsert strategies? - 10-28-2008 , 01:19 PM



On Oct 26, 4:10*am, "gym dot scuba dot kennedy at gmail"
<kenned... (AT) verizon (DOT) net> wrote:
Quote:
m... (AT) pixar (DOT) com> wrote in message

news:JlUMk.3915$D32.1708 (AT) flpi146 (DOT) ffdc.sbc.com...



So far, I've figured out 4 possible ways to perform upsert-like
functionality:

1. try insert, on exception update
2. try update, on exception insert
3. delete, then insert
4. merge with DUAL

It seems so far the nicest solution is #4.

Here's some questions:

- Do the other methods have any features which might recommend them?

- Are there any methods that might be portable to other databases?

- Are there any methods I might be overlooking?

Many TIA!
Mark

--
Mark Harrison
Pixar Animation Studios

#2 won't work. *You will update 0 rows which isn't an error.
#3 is terrible. *You are generating a lot more redo etc. than you need to.
Just use the merge statement. *I don't see what dual has to do with it.*You
should be able to do it in one statement.
Jim- Hide quoted text -

- Show quoted text -
The issue here is to perform a MERGE using only one table, not two,
hence the use of DUAL. Out of all of the listed possibilities the
actual MERGE, using DUAL, is your best bet:

merge into employee e
using (select 20 as id from dual) i on (e.id = i.id)
when matched then
update
set salary = salary + 10000
when not matched then
insert
values('BLORPO',20,12000)
/

You'll not find anything useful in this regard that is portable; then,
why do you need it to be? You're better served by writing to the dbms
in use, not attempting to generate 'universal' code which likely won't
scale nor will it perform.


David Fitzjarrell


Reply With Quote
  #10  
Old   
Frank van Bortel
 
Posts: n/a

Default Re: upsert strategies? - 11-12-2008 , 12:30 PM



mh (AT) pixar (DOT) com wrote:
Quote:
So far, I've figured out 4 possible ways to perform upsert-like
functionality:

1. try insert, on exception update
2. try update, on exception insert
3. delete, then insert
4. merge with DUAL

It seems so far the nicest solution is #4.

Here's some questions:

- Do the other methods have any features which might recommend them?

- Are there any methods that might be portable to other databases?

- Are there any methods I might be overlooking?

Many TIA!
Mark

Search asktom.oracle.com for "upsert" - he has documented, timed
examples of why you should use merge

--

Regards,
Frank van Bortel


Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.