> 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/19/internals/overview/rule-system.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# 51.4. PostgreSQL 規則系統

### 51.4. PostgreSQL 規則系統 [#](#rule-system) <a href="#rule-system" id="rule-system"></a>

PostgreSQL 支援強大的*規則系統*，可用來定義*檢視表*與模稜兩可的*檢視表更新*。 最初 PostgreSQL 規則系統有兩種實作：

* 第一種使用*資料列層級*處理，並深植於*執行器*中。每當存取個別資料列時，規則系統便會被呼叫。這項實作在 1995 年 Berkeley Postgres 專案的最後一個正式版本轉為 Postgres95 時移除。
* 第二種規則系統實作是一種稱為*查詢重寫*的技術。*重寫系統*是一個位於*剖析器階段*與*規劃器／最佳化器*之間的模組，至今仍在實作中。

[第 39 章](https://docs.postgresql.tw/19/server-programming/rules.md)已詳細討論查詢重寫器，因此此處不再說明。我們僅指出，重寫器的輸入與輸出都是查詢樹；也就是說，樹的表示法與語意細節層級不會改變。重寫可視為一種巨集展開。

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/rule-system.html)（原文版本：18.6；核對日期：2026-09-10）


---

# 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/19/internals/overview/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.
