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

# 39.6. 規則與指令狀態 \#

### 39.6. 規則與指令狀態 [#](#rules-status) <a href="#rules-status" id="rules-status"></a>

PostgreSQL 伺服器對於它所收到的每一個指令，都會回傳一個指令狀態字串，例如 `INSERT 149592 1`。在沒有牽涉到規則時，這很單純；但是當查詢被規則重寫時，會發生什麼事呢？

規則對指令狀態的影響如下：

* 如果該查詢沒有無條件的 `INSTEAD` 規則，那麼原本給定的查詢就會被執行，其指令狀態也會照常回傳。（但請注意，如果存在任何有條件的 `INSTEAD` 規則，其限定條件的否定形式會被加到原始查詢上。這可能會減少它所處理的資料列數量，若是如此，回報的狀態也會受到影響。）
* 如果該查詢有任何無條件的 `INSTEAD` 規則，那麼原始查詢完全不會被執行。在這種情況下，伺服器會回傳最後一個由 `INSTEAD` 規則（不論有條件或無條件）所加入、且與原始查詢屬於相同指令型別（`INSERT`、`UPDATE` 或 `DELETE`）之查詢的指令狀態。如果沒有任何規則加入符合這些條件的查詢，那麼回傳的指令狀態會顯示原始查詢的型別，而資料列數與 OID 欄位則為零。

在第二種情況下，程式設計師可以讓自己想要的那個 `INSTEAD` 規則成為設定指令狀態的規則：只要在所有生效的規則中，給它一個依字母順序排在最後的規則名稱，它就會最後被套用。

***

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


---

# 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/server-programming/rules/rules-status.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.
