In this section, we will look at how a trigger can be used to modify manipulated data according to specific rules. For example, what happens if the type of the file (f_type) is not specified when a tuple is inserted or updated? It might be possible to infer the file type from its name extension. In order to do this, a row-level trigger must be implemented; the trigger will fire before any INSERT or UPDATE completes, and this will allow you to modify each tuple on the fly, inspect the current value of the incoming or updating f_name value, and extract the file type from its extension.
The trigger function is shown in Listing 7. First, it checks its running context to ensure the function has not been ...