soulfly1983
soulfly1983

Reputation: 177

DB2 conditional import

I have two DB2 databases (Database1 and Database2) both containing a table called SubscriptionTable. Both tables contain user subscription related data and the columns of SubscriptionTable are the same in both databases.

Now I need to copy (and overwrite) data from Database1.SubscriptionTable to Database2.SubscriptionTable but only if the LAST_UPDATED_TIMESTAMP column in Database2.SubscriptionTable is not greater than a specific date.

So in short I would like to overwrite subscription data in Database2.SubscriptionTable but only if the data was NOT modified after a specific date.

Could I use existing utility for this purpose, e.g. db2 import where I could also specify a condition (LAST_UPDATED_TIMESTAMP < 'XXXX-XX-XX') for each row being overwritten ?

Upvotes: 0

Views: 623

Answers (1)

Ian Bjorhovde
Ian Bjorhovde

Reputation: 11042

The DB2 IMPORT utility does not have the ability to ignore rows based on what is in them.

The "easiest" way to do this would be, as Gordon Linoff suggests in the comments, would be via federation, so Database1.SubscriptionTable is accessible from within Database2.

Alternatively, you could simply export the data from Database1 that meets your criteria:

-- Connect to Database1
export to data.del of del select * from SubscriptionTable 
                           where last_updated_timestamp > ...

-- Connect to Database2
import from data.del of del insert into SubscriptionTable ...

Upvotes: 1

Related Questions