Difference between Insert else Update and Update else insert

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
Anand K
Participant
Posts: 17
Joined: Thu Nov 20, 2003 7:19 am

Difference between Insert else Update and Update else insert

Post by Anand K »

Hi All

Can any one suggest on which all situations we need to use the "Insert new rows or Update existing rows" and "Update existing rows and Insert new rows" in ORAOCI8 Stage?


Thanks in Advance
Anand
Sridhar G
Participant
Posts: 2
Joined: Wed Dec 22, 2004 2:32 am

Post by Sridhar G »

Hi Anand,
From the experience that we have had, i feel it is better to use Update else Insert b'coz, if you update first, whenever a matching record is found, it immediately updates and goes to the next record. Else, it waits till all the insert is completed and then only updates.
Anand K
Participant
Posts: 17
Joined: Thu Nov 20, 2003 7:19 am

Post by Anand K »

Thanks for the quick response, Sridhar.

So what I understand is for records running into millions, we need to use the Update else Insert and for smaller amount of data we need to use Insert else Update.

Anand
ogmios
Participant
Posts: 659
Joined: Tue Mar 11, 2003 3:40 pm

Post by ogmios »

"Insert else update" will first try to insert the row and if that fails try to update. "Update else insert" will first try the update and if that fails (no corresponding row exists) the insert.

If you have the keys defined in your database and DataStage in a proper way both are the same qua functionality. But e.g. if would use them on a table without keys on the database (but with 'correct' keys defined in DataStage) you will see differences: "Insert else update" would then always succeed on the insert (since it would never get a duplicate error from the database) and insert duplicate rows, while the "Update else insert" would still work properly (in the case that the keys are defined properly in DataStage).

In the assumption that the keys are correctly defined in database and DataStage the rule would be:
- If you know most of your input rows are updates use "Update else Insert"
- If you know most of your input rows are new inserts use "Insert else Update"

Ogmios

P.S. Don't know what the comment was on waiting till insert is complete :wink: . I do know that in Oracle actually updating something is much slower as inserting.
In theory there's no difference between theory and practice. In practice there is.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

All in all, you are much better off not using either of them. IMHO. :wink: Best to make explicit reference checks so you know which is which and split your output stream, doing seperate inserts and updates.

And as ogmios notes, it is vital that the indexes on your target table support these mixed actions.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply