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

# 52.45. pg\_rewrite \#

### 52.45. `pg_rewrite` [#](#catalog-pg-rewrite) <a href="#catalog-pg-rewrite" id="catalog-pg-rewrite"></a>

系統目錄 `pg_rewrite` 存放資料表與檢視表的重寫規則。

#### 表 52.45. `pg_rewrite` 欄位 [#](#catalog-pg-rewrite-columns) <a href="#catalog-pg-rewrite-columns" id="catalog-pg-rewrite-columns"></a>

| <p>欄位類型</p><p>說明</p>                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><code>oid</code> <code>oid</code></p><p>資料列識別碼</p>                                                                                                                                                                                                                                                                                                                                                                                            |
| <p><code>rulename</code> <code>name</code></p><p>規則名稱</p>                                                                                                                                                                                                                                                                                                                                                                                        |
| <p><code>ev\_class</code> <code>oid</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-class.md"><code>pg\_class</code></a>.<code>oid</code>）</p><p>此規則所屬的資料表</p>                                                                                                                                                                                                                                                   |
| <p><code>ev\_type</code> <code>char</code></p><p>此規則所適用的事件類型：1 = <a href="https://docs.postgresql.tw/19/reference/sql-commands/sql-select.md">SELECT</a>、2 = <a href="https://docs.postgresql.tw/19/reference/sql-commands/sql-update.md">UPDATE</a>、3 = <a href="https://docs.postgresql.tw/19/reference/sql-commands/sql-insert.md">INSERT</a>、4 = <a href="https://docs.postgresql.tw/19/reference/sql-commands/sql-delete.md">DELETE</a></p> |
| <p><code>ev\_enabled</code> <code>char</code></p><p>控制規則在哪些 <a href="https://docs.postgresql.tw/19/server-administration/runtime-config/runtime-config-client.md#GUC-SESSION-REPLICATION-ROLE">session\_replication\_role</a> 模式下觸發。<code>O</code> = 規則在 “origin” 與 “local” 模式下觸發，<code>D</code> = 規則已停用，<code>R</code> = 規則在 “replica” 模式下觸發，<code>A</code> = 規則一律觸發。</p>                                                                       |
| <p><code>is\_instead</code> <code>bool</code></p><p>若此規則為 <code>INSTEAD</code> 規則，則為真</p>                                                                                                                                                                                                                                                                                                                                                        |
| <p><code>ev\_qual</code> <code>pg\_node\_tree</code></p><p>規則限定條件的運算式樹（以 <code>nodeToString()</code> 表示法的形式）</p>                                                                                                                                                                                                                                                                                                                                 |
| <p><code>ev\_action</code> <code>pg\_node\_tree</code></p><p>規則動作的查詢樹（以 <code>nodeToString()</code> 表示法的形式）</p>                                                                                                                                                                                                                                                                                                                                  |

<br>

#### 注意

若資料表在此系統目錄中有任何規則，`pg_class.relhasrules` 必須為真。

***

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


---

# 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/catalogs/catalog-pg-rewrite.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.
