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

# 52.58. pg\_trigger \#

### 52.58. `pg_trigger` [#](#catalog-pg-trigger) <a href="#catalog-pg-trigger" id="catalog-pg-trigger"></a>

目錄 `pg_trigger` 儲存資料表與檢視表上的觸發程序。詳細資訊請參閱 [CREATE TRIGGER](https://docs.postgresql.tw/19/reference/sql-commands/sql-createtrigger.md)。

#### 表 52.58. `pg_trigger` 欄位 [#](#catalog-pg-trigger-columns) <a href="#catalog-pg-trigger-columns" id="catalog-pg-trigger-columns"></a>

| <p>欄位類型</p><p>說明</p>                                                                                                                                                                                                                                                                                                                                                             |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><code>oid</code> <code>oid</code></p><p>資料列識別碼</p>                                                                                                                                                                                                                                                                                                                            |
| <p><code>tgrelid</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>tgparentid</code> <code>oid</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-trigger.md"><code>pg\_trigger</code></a>.<code>oid</code>）</p><p>此觸發程序複製自的父觸發程序（在建立分割區或將分割區附加到分割資料表時會發生）； 若不是複製而來則為零</p>                                                                                                                                    |
| <p><code>tgname</code> <code>name</code></p><p>觸發程序名稱（在同一資料表的觸發程序中必須唯一）</p>                                                                                                                                                                                                                                                                                                      |
| <p><code>tgfoid</code> <code>oid</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-proc.md"><code>pg\_proc</code></a>.<code>oid</code>）</p><p>要呼叫的函式</p>                                                                                                                                                                                           |
| <p><code>tgtype</code> <code>int2</code></p><p>識別觸發程序觸發條件的位元遮罩</p>                                                                                                                                                                                                                                                                                                               |
| <p><code>tgenabled</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>tgisinternal</code> <code>bool</code></p><p>若觸發程序為內部產生（通常是為了強制執行 <code>tgconstraint</code> 所識別的限制條件），則為真</p>                                                                                                                                                                                                                                                            |
| <p><code>tgconstrrelid</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>tgconstrindid</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>tgconstraint</code> <code>oid</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-constraint.md"><code>pg\_constraint</code></a>.<code>oid</code>）</p><p>與觸發程序相關聯的 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-constraint.md"><code>pg\_constraint</code></a> 項目 （若觸發程序不是用於限制條件，則為零）</p>                           |
| <p><code>tgdeferrable</code> <code>bool</code></p><p>若限制條件觸發程序可延遲，則為真</p>                                                                                                                                                                                                                                                                                                        |
| <p><code>tginitdeferred</code> <code>bool</code></p><p>若限制條件觸發程序初始即延遲（initially deferred），則為真</p>                                                                                                                                                                                                                                                                                |
| <p><code>tgnargs</code> <code>int2</code></p><p>傳給觸發程序函式的引數字串數目</p>                                                                                                                                                                                                                                                                                                              |
| <p><code>tgattr</code> <code>int2vector</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-attribute.md"><code>pg\_attribute</code></a>.<code>attnum</code>）</p><p>若觸發程序限定於特定欄位，則為欄位編號；否則為空陣列</p>                                                                                                                                                   |
| <p><code>tgargs</code> <code>bytea</code></p><p>要傳給觸發程序的引數字串，每個都以 NULL 結尾</p>                                                                                                                                                                                                                                                                                                    |
| <p><code>tgqual</code> <code>pg\_node\_tree</code></p><p>以 <code>nodeToString()</code> 表示法呈現的觸發程序 <code>WHEN</code> 條件運算式樹，若無則為 null</p>                                                                                                                                                                                                                                         |
| <p><code>tgoldtable</code> <code>name</code></p><p><code>REFERENCING</code> 子句中 <code>OLD TABLE</code> 的名稱， 若無則為 null</p>                                                                                                                                                                                                                                                        |
| <p><code>tgnewtable</code> <code>name</code></p><p><code>REFERENCING</code> 子句中 <code>NEW TABLE</code> 的名稱， 若無則為 null</p>                                                                                                                                                                                                                                                        |

<br>

目前只有 `UPDATE` 事件支援限定欄位的觸發，因此 `tgattr` 只與該事件類型相關。`tgtype` 也可能包含其他事件類型的位元，但無論 `tgattr` 的內容為何，這些事件類型都被視為作用於整個資料表。

#### 注意

當 `tgconstraint` 不為零時，`tgconstrrelid`、`tgconstrindid`、`tgdeferrable` 與 `tginitdeferred` 大致上與所參照的 [`pg_constraint`](https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-constraint.md) 項目重複。不過，不可延遲的觸發程序有可能與可延遲的限制條件相關聯：外鍵限制條件可以同時擁有一些可延遲的觸發程序與一些不可延遲的觸發程序。

#### 注意

若某個關聯在此目錄中有任何觸發程序，`pg_class.relhastriggers` 必須為真。

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/catalog-pg-trigger.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-trigger.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.
