> For the complete documentation index, see [llms.txt](https://docs.postgresql.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.postgresql.tw/server-programming/rules.md).

# Chapter 39. The Rule System

**Table of Contents**

[39.1. The Query Tree](/server-programming/rules/querytree.md)

[39.2. Views and the Rule System](/server-programming/rules/rules-views.md) : [39.2.1. How `SELECT` Rules Work](/server-programming/rules/rules-views.md#RULES-SELECT)

```
[39.2.2. View Rules in Non-`SELECT` Statements](rules-views.md#RULES-VIEWS-NON-SELECT)

[39.2.3. The Power of Views in PostgreSQL](rules-views.md#RULES-VIEWS-POWER)

[39.2.4. Updating a View](rules-views.md#RULES-VIEWS-UPDATE)
```

[39.3. Materialized Views](/server-programming/rules/rules-materializedviews.md)

[39.4. Rules on `INSERT`, `UPDATE`, and `DELETE`](/server-programming/rules/rules-update.md) : [39.4.1. How Update Rules Work](/server-programming/rules/rules-update.md#RULES-UPDATE-HOW)

```
[39.4.2. Cooperation with Views](rules-update.md#RULES-UPDATE-VIEWS)
```

[39.5. Rules and Privileges](/server-programming/rules/rules-privileges.md)

[39.6. Rules and Command Status](/server-programming/rules/rules-status.md)

[39.7. Rules Versus Triggers](/server-programming/rules/rules-triggers.md)

This chapter discusses the rule system in PostgreSQL. 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 PostgreSQL, 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\]](/bibliography.md#STON90B) and [\[ong90\]](/bibliography.md#ONG90).

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/rules.html)（英文原文，待翻譯）


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.postgresql.tw/server-programming/rules.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
