Update vs Insert in ETL

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
seell
Participant
Posts: 22
Joined: Fri Nov 07, 2003 9:46 pm

Update vs Insert in ETL

Post by seell »

hi
I seem to encoutner a curious situation when trying to update a table (key, code, desc). My intent is to update if the code exist else insert.

The table is first extracted out with the key and code as lookup.
Transformation logic as follows
Input file (code, desc) has 2 rows of the same code.
The first row is updated into the table
The 2nd row is inserted (this should still be update ??)

I have used the check in the transformation for the key : if code exist use the key for the code else insert with key = @OUTROWNUM
Processing option for the table : update existing or insert new rows.

Thank you
Regards
SLL
Amos.Rosmarin
Premium Member
Premium Member
Posts: 385
Joined: Tue Oct 07, 2003 4:55 am

Post by Amos.Rosmarin »

Hi,

If i'm following you correctly you have a stream input data you want to put in a database table where some of the rows exists and therefor need to be updated whiole the others are new and need to be inserted.

If so you have 2 options:
1. Mark the key column as your key in the column properties and use the 'insert new or update existing' option (or the opposite ).
2. Read only the key column from your target table into hash file.
Do a key lookup using the hash a reference. If the lookup.NOTFOUND = @TRUE goto an insert step else (found) it's an update.
If you source can have duplicate new record there is a risk of doing multiple inserts with the same key. In this case you must do a lookup on the table itself with dirty read or commit after each row.


HTH,
Amos
Peytot
Participant
Posts: 145
Joined: Wed Jun 04, 2003 7:56 am
Location: France

Post by Peytot »

Why do you not use the Option Upsert ( = Update or Insert). If you have the same description of your two flows, you can do an Upsert. DataStage checks for you if the row already exist or not.
Like that, you are nothing to put in your constraint and you have one file.

Pey
clshore
Charter Member
Charter Member
Posts: 115
Joined: Tue Oct 21, 2003 11:45 am

Post by clshore »

I didn't see that you specified what DB you are using.
Oracle 9i supports 'upsert' and so does the DS OCI9 stage.
The DS version is a bit restrictive (updates when PK's match, else inserts).
Although the actual Orcale SQL statement that implements upsert is a bit more complex (merge?, see the docs), it can be coded. In fact, I've already had to roll some custom SQL, as my requirements called for more than simple PK equality.

Carter
seell
Participant
Posts: 22
Joined: Fri Nov 07, 2003 9:46 pm

Post by seell »

I am using Oracle 9.2.0.4;
Where could I find the relevant documentation on upsert ?? I could not find it in the Datastage designer manual.

Thank you
Regards
Teej
Participant
Posts: 677
Joined: Fri Aug 08, 2003 9:26 am
Location: USA

Post by Teej »

seell wrote:I am using Oracle 9.2.0.4;
Where could I find the relevant documentation on upsert ?? I could not find it in the Datastage designer manual.

Thank you
Regards
Oooooooo, 9.2.0.4. *winces* DataStage 6x is not very... perfectly compatible with Oracle 9.2.0.3 and 9.2.0.4. In our brief voyage onto that version from 9.2.0.2, we caught three individual critical issues with 6.0r3 that was only partly addressed on 6.0.1. Oracle decided to majorly change their behavior for 9.2.0.3 compared to 9.2.0.2 that goes against the general understanding that Ascential developers had when working with Oracle. The issues caused us to regress to 9.2.0.2.

I do not think Ascential currently support that particular version for 6x, although I believe it is fully addressed for 7x. So, your unusual behavior observation could be yet another bug caused by the change between 9.2.0.2 and 9.2.0.4.

-T.J.
Developer of DataStage Parallel Engine (Orchestrate).
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

T.J. -

Care to elaborate on the issues you found? We are running the version mix you noted (9.2.0.4 and 6.0.1) on HP/UX and now you've got me a little... scared. :wink: Or was any of this specific to Tru64?
-craig

"You can never have too many knives" -- Logan Nine Fingers
mhester
Participant
Posts: 622
Joined: Tue Mar 04, 2003 5:26 am
Location: Phoenix, AZ
Contact:

Post by mhester »

We have been running this combination (DS 6x and 9.2.0.4) for quite some time (August) and have not experienced any problems with DS or Oracle. This may be platform specific. We are a Sun running Solaris 8.

Regards,

Michael Hester
Teej
Participant
Posts: 677
Joined: Fri Aug 08, 2003 9:26 am
Location: USA

Post by Teej »

chulett wrote:T.J. -

Care to elaborate on the issues you found? We are running the version mix you noted (9.2.0.4 and 6.0.1) on HP/UX and now you've got me a little... scared. :wink: Or was any of this specific to Tru64?
Now that I'm at work, I can dig out the specifics that we found. We only located it with regards to PX programming, especially with CustomOPS stages.

First of all, it was 9.2.0.3 and 9.2.0.1, so my apologies.

1. Oracle's Partitioned Table would not work. This was supposed to be fixed for 6.0.1.

2. If you use Number on Oracle, it is imported differently using 9.2.0.3 compared to 9.2.0.1. This really affect CustomOPS stages we had using Orchestrate libraries. On 9.2.0.3, they see it as Int32. On 9.2.0.1, they see it as Decimal[38,10]. This is supposed to be fixed for 7.0.

3. Related to #2, the way Oracle report NULL for length of fields, the value was changed. Well, actually, two values were supposed to be provided for 9.2.0.1, and the one that Ascential was using was removed for 9.2.0.2. At least that is what my fuzzy memory claims.

* * *

When we found out that the fix was slated for 7.0, we pretty much rolled back, without investigating other strange behaviors with PX and 9.2.0.3. We have not upgraded to either 7.0 or 9.2.0.3 since then, so I do not know if everything was perfectly addressed.

So when I saw this post, those nasty flashbacks came rushing back last night. Hehe. We spent a week trying to figure out what was going on until the DBA finally piped up, "Oh, we upgraded..."

-T.J.
Developer of DataStage Parallel Engine (Orchestrate).
Post Reply