Chapter 44. The Rule System

Table of Contents

44.1. The Query Tree
44.2. Views and the Rule System
44.2.1. How SELECT Rules Work
44.2.2. View Rules in Non-SELECT Statements
44.2.3. The Power of Views in Postgres Pro
44.2.4. Updating a View
44.3. Materialized Views
44.4. Rules on INSERT, UPDATE, and DELETE
44.4.1. How Update Rules Work
44.4.2. Cooperation with Views
44.5. Rules and Privileges
44.6. Rules and Command Status
44.7. Rules Versus Triggers

This chapter discusses the rule system in Postgres Pro. Production rule systems are conceptually simple, but there are many subtle points involved in actually using them.

Some other database systems define active database rules, which are usually stored procedures and triggers. In Postgres Pro, these can be implemented using functions and triggers as well.

The rule system (more precisely speaking, the query rewrite rule system) is totally different from stored procedures and triggers. It modifies queries to take rules into consideration, and then passes the modified query to the query planner for planning and execution. It is very powerful, and can be used for many things such as query language procedures, views, and versions. The theoretical foundations and the power of this rule system are also discussed in [ston90b] and [ong90].