Replace existing rows

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

sheema
Premium Member
Premium Member
Posts: 204
Joined: Sat Jul 22, 2006 10:20 am

Replace existing rows

Post by sheema »

I have job which reads data from a abc.txt and loads into oraOCI i am using the update action -Replace existing rows into TableA which has 2 key columns.

But now i need to delete the rows depending on only one key and than insert the rows.so how can do this most efficiently.

Thanks
sheema
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

You need to replace based on single column, am I right?
Mark that single column alone as key in Datastage.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
sheema
Premium Member
Premium Member
Posts: 204
Joined: Sat Jul 22, 2006 10:20 am

Post by sheema »

If i make single column as key,than if i get 2 rows with same key1 and different col2, i.e

1001,sdfg
1001,wvdf

than would'nt it be a problem with Unique constraint.
Oracle will reject the second row.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

What you expect the output should be for this case?
If there is any record with 1001, it should be replaced with these two records?
And by the way, the database keys has not been changed, only are just marking the key in datastage as one key.
But to be more comfortable, you can do a lookup to the target and replace the rows with the input rows, if not found, insert it.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
sheema
Premium Member
Premium Member
Posts: 204
Joined: Sat Jul 22, 2006 10:20 am

Post by sheema »

ok,i want to delete both the 1001 records in the Tbl and insert the new record from the source file.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Have you tried the option "Replace Existing Row completely" with single filed marked as Key in Datastage.
Observer the SQL generated, a DELETE statement will be issued first with the condition, Where Col1 = :1 (Single field).
Later Insert statement.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
sheema
Premium Member
Premium Member
Posts: 204
Joined: Sat Jul 22, 2006 10:20 am

Post by sheema »

yes,that is working fine.I need another clarification
Previously we had 2 jobs

Job1,we read from the source file and than
we used a aggregator to group by on key1 and delete the records from tabl1.

Job2,we read from the same source file and insert the rows into tabl1.

So instead of 2 jobs i am combining them into a single job,by using the update action as 'Replace existing rows completely' and as you suggested by taking a single key column in oraOCI.i just want to make sure that i am right by replacing 2 jobs with a single job.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

I don't get you full business logic on why is it all been done.
Just be aware that, if your input have more that 1 row with the same key value say 1001, you will end up in inserting only the latest one. Where I guess you need to insert both of them.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
sheema
Premium Member
Premium Member
Posts: 204
Joined: Sat Jul 22, 2006 10:20 am

Post by sheema »

ok,Kumar .Thanks for you help.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

If you think its resolves your issue, you can mark the topic as resolved.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

kumar_s wrote:Just be aware that, if your input have more that 1 row with the same key value say 1001, you will end up in inserting only the latest one. Where I guess you need to insert both of them.
Make sure you understand what Kumar is saying. A second occurance of a key value in your input source will delete the first value that you just inserted!
-craig

"You can never have too many knives" -- Logan Nine Fingers
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

I should better learn to phrase sentences clearly.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
sheema
Premium Member
Premium Member
Posts: 204
Joined: Sat Jul 22, 2006 10:20 am

Post by sheema »

ok,but when just select key1 as key in oraOCI and run the job
i am getting the warning

ORA-01008: not all variables bound
sheema
Premium Member
Premium Member
Posts: 204
Joined: Sat Jul 22, 2006 10:20 am

Post by sheema »

for example if i have 2 rows

1001,wed
1001,mnb

what i understand is only 2nd row will be inserted into table,if i select 1001 as key and update action as 'Replace existing completely'.Am i right?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Technically, no. The end result is the same, but what actually happens would be this:

1) 1001,wed. Any existing records with 1001 in that field will be deleted then this record will be inserted.
2) 1001,mnb. Any existing records with 1001 in that field (now meaning the "1001,wed" record) will be deleted then this record will be inserted.
-craig

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