Functions and Triggers
So far in this chapter, you have discovered how to quantify query performance via the Query Planner. In this section, you will construct reusable queries and statements via functions, as well as automatic function execution via trigger callbacks. The combination of these two SQL features can be used to not only run queries or re-index tables as data is added to, updated in, or removed from the database but also run hypothesis tests and track their results throughout the life of the database.
As in almost all other programming or scripting languages, functions in SQL are contained sections of code that provide a lot of benefits, such as efficient code reuse and simplified troubleshooting processes. You can use functions to repeat or modify statements or queries without re-entering the statement each time or searching for its use throughout longer code segments. One of the most powerful aspects of functions is that they allow you to break...