> 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/12/server-programming/the-rule-system.md).

# 40. 規則系統

本章討論 PostgreSQL中的規則系統（rule system）。產品的規則系統在概念上很簡單，但實際使用它們會涉及許多細微的觀點。

其他一些資料庫系統定義了有效的資料庫規則，這些規則通常是儲存過程和觸發器。在 PostgreSQL 中，這些可以使用函數和觸發器來達成。

規則系統（更確切地說，查詢覆寫規則系統）與儲存過程和觸發器完全不同。它以規則修改查詢，然後將修改的查詢傳遞給查詢規劃器進行規劃和執行。它的功能非常強大，可用於查詢語言程序、view 和版本等多種功能。\[[ston90b](/12/bibliography.md)] 和 \[[ong90](/12/bibliography.md)] 也討論了這個規則系統的理論基礎和能力。


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.postgresql.tw/12/server-programming/the-rule-system.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
