May 2018
Intermediate to advanced
576 pages
30h 25m
English
In the rule-based example, we use the COALESCE function, which returns the first argument, if not null, or the second one otherwise. When the original INSERT statement does not specify a value in meters, then it uses the value in feet divided by 0.3048.
The second rule sets the value in meters to different expressions—if the value in meters was updated we use the new one; if the value in feet was updated, we use the new value in feet divided by 0.3048, and otherwise we use the old value in meters (that is, we don’t change it).
The logic implemented in the trigger function is similar to the one above: note that we use the TG_OP automatic variable to handle INSERT and UPDATE separately.
We've just scratched the surface of what ...