DIET: DELETE + INSERT instead of UPDATE
Gary Sherman
June 30, 2015

When we have to insert, update, or delete data, DIET (Dovetail ArchiveManager) is often the tool of choice.

Updating an object

Typically, when we want to update some data, we just need to define its uniqueness properly.

For example, if I wanted to update a business rule property name,  I could define its uniqueness as a combination of its object type + name.

For example:

If I used DIET to import this file, and this prop_name  record didn’t exist in the database, then it would do an INSERT, which would create this prop_name record.

If I used DIET to import this file, and this prop_name record did exist in the database, then it would do an UPDATE, which would update the existing prop_name record. This would allow me to update the path or max length of that rule property.

This syntax allows us to update the non-unique fields of a record.

Updating the unique fields

Updating a unique field on an object is not always as straight-forward.

A common way to do this is to delete the existing record by using the PURGE option of DIET, and then doing a second DIET IMPORT run to insert the new record. It’s two operations, but it works. This only works if you don’t have any foreign keys that reference the object that you’re deleting.

A second option is to use objid as a unique field, as that doesn’t change. But use of objids can cause problems when using the same file on different databases. So the import file may work in your development database, but not production.

A third option is a seldom-used feature of DIET, which allows a  DELETE + an INSERT in one operation. This is a cool little trick that not everyone knows about. Again, this only works if you don’t have any foreign keys that reference the object that you’re deleting.

Update daylight savings time records

A real-world example of this is updating the daylight savings time records. When the start and end dates for daylight savings changed starting in 2007, those daylight_hr records needed to be updated.

The uniqueness for daylight_hr records was the combination of start_time + the relation to the time_zone.

But since we want to change the start_time (and end_time), we can’t use the standard syntax. And since no other tables have foreign keys that point to daylight_hr, we can do this DELETE + INSERT trick in one file.

Here’s an example:

We can have all that information in one DAT file, and use DIET’s import option. DIET will DELETE the old daylight_hr record, INSERT a new one with the correct dates, and RELATE it to the correct time_zone.

And we can do this with just one DAT file, and one execution run of DIET. Pretty cool.

As I mentioned, that DELETE element is rarely used, but can be super useful in certain circumstances. The DIET documentation has more details on the DELETE element.

Just one more tool to add to your bag of tricks.

Leave a Comment

International: +1 (512) 610-5400
Toll Free: 1 (800) 684-2055