> 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/the-sql-language/functions/functions-event-triggers/pg-event-trigger-table-rewrite-functions.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# 9.30.3. 處理資料表改寫事件

## 9.30.3. 處理資料表改寫事件 [#](#pg-event-trigger-table-rewrite-functions) <a href="#pg-event-trigger-table-rewrite-functions" id="pg-event-trigger-table-rewrite-functions"></a>

[表 9.111](#functions-event-trigger-table-rewrite) 所列的函式，提供剛觸發 `table_rewrite` 事件之資料表的相關資訊。如果在任何其他情境中呼叫，就會引發錯誤。

### 表 9.111. 資料表改寫資訊函式 [#](#functions-event-trigger-table-rewrite) <a href="#functions-event-trigger-table-rewrite" id="functions-event-trigger-table-rewrite"></a>

| <p>函式</p><p>說明</p>                                                                                                                                                                                                                    |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><code>pg\_event\_trigger\_table\_rewrite\_oid</code> () → <code>oid</code></p><p>回傳即將被改寫之資料表的 OID。</p>                                                                                                                             |
| <p><code>pg\_event\_trigger\_table\_rewrite\_reason</code> () → <code>integer</code></p><p>回傳說明改寫原因的代碼。其值是由下列值組成的點陣圖：<code>1</code>（資料表的持久性已改變）、<code>2</code>（欄位的預設值已改變）、<code>4</code>（欄位有新的資料型別）以及 <code>8</code>（資料表存取方法已改變）。</p> |

<br>

這些函式可以像這樣在事件觸發程序中使用：

```

CREATE FUNCTION test_event_trigger_table_rewrite_oid()
 RETURNS event_trigger
 LANGUAGE plpgsql AS
$$
BEGIN
  RAISE NOTICE 'rewriting table % for reason %',
                pg_event_trigger_table_rewrite_oid()::regclass,
                pg_event_trigger_table_rewrite_reason();
END;
$$;

CREATE EVENT TRIGGER test_table_rewrite_oid
                  ON table_rewrite
   EXECUTE FUNCTION test_event_trigger_table_rewrite_oid();
```

[返回 9.30. 事件觸發程序函式](https://docs.postgresql.tw/19/the-sql-language/functions/functions-event-triggers.md#functions-event-triggers)

***

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


---

# 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/the-sql-language/functions/functions-event-triggers/pg-event-trigger-table-rewrite-functions.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.
