Database Reference
In-Depth Information
Triggers, Rules, and Views
You have learned to code and use functions in Chapter 2 , The Procedural Language .
These functions were called explicitly using the SELECT function() command.
When a database grows, so does the complexity. You can't be there all time to monitor,
implement, or troubleshoot what your database should do before or after a speciic
database event. For example, you do not want your customers to enter values against
speciic constraints you deined, or on inserting, updating, and deleting values, you
want to have a function that can take care of modiications that have been made and
make audit logs of all such operations.
A function with the capability to execute on its own when a certain event occurs is
called a trigger function ; this is executed when a trigger is ired against a speciic
database event.
In PostgreSQL, we have rules ; certain tasks that can be done with triggers are
achieved by these rules. Rules are used to implement views in PostgreSQL. Views
are virtual tables that help to group data from one or more tables.
This chapter is important as it helps us to learn and understand how triggers, rules,
and views can be signiicant in a database design. Understanding their meaning and
signiicance is the key to their appropriate usage.
This chapter will cover the following topics:
• Triggers—creating trigger functions and usage
• Creating trigger functions in native PostgreSQL languages
• What PostgreSQL rules are and triggers versus rules
• Views—creating views and materialized views
Search WWH ::




Custom Search