> 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/internals/catalogs/catalog-pg-trigger.md).

# 52.58. pg\_trigger \#

The catalog `pg_trigger` stores triggers on tables and views. See [CREATE TRIGGER](/reference/sql-commands/sql-createtrigger.md) for more information.

**Table 52.58. `pg_trigger` Columns**

| <p>Column Type</p><p>Description</p>                                                                                                                                                                                                                                                                                                                                                            |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><code>oid</code> <code>oid</code></p><p>Row identifier</p>                                                                                                                                                                                                                                                                                                                                   |
| <p><code>tgrelid</code> <code>oid</code> (references <a href="/pages/b1fii6hWVNacZFXaxWON"><code>pg\_class</code></a>.<code>oid</code>)</p><p>The table this trigger is on</p>                                                                                                                                                                                                                  |
| <p><code>tgparentid</code> <code>oid</code> (references <a href="/pages/xl31tj2BwYYSUh6VpwdK"><code>pg\_trigger</code></a>.<code>oid</code>)</p><p>Parent trigger that this trigger is cloned from (this happens when partitions are created or attached to a partitioned table); zero if not a clone</p>                                                                                       |
| <p><code>tgname</code> <code>name</code></p><p>Trigger name (must be unique among triggers of same table)</p>                                                                                                                                                                                                                                                                                   |
| <p><code>tgfoid</code> <code>oid</code> (references <a href="/pages/8TiLY9QeJalZY0OBAANF"><code>pg\_proc</code></a>.<code>oid</code>)</p><p>The function to be called</p>                                                                                                                                                                                                                       |
| <p><code>tgtype</code> <code>int2</code></p><p>Bit mask identifying trigger firing conditions</p>                                                                                                                                                                                                                                                                                               |
| <p><code>tgenabled</code> <code>char</code></p><p>Controls in which <a href="/pages/kv4bHT02CeSrSMpfX0AZ#GUC-SESSION-REPLICATION-ROLE">session\_replication\_role</a> modes the trigger fires. <code>O</code> = trigger fires in “origin” and “local” modes, <code>D</code> = trigger is disabled, <code>R</code> = trigger fires in “replica” mode, <code>A</code> = trigger fires always.</p> |
| <p><code>tgisinternal</code> <code>bool</code></p><p>True if trigger is internally generated (usually, to enforce the constraint identified by <code>tgconstraint</code>)</p>                                                                                                                                                                                                                   |
| <p><code>tgconstrrelid</code> <code>oid</code> (references <a href="/pages/b1fii6hWVNacZFXaxWON"><code>pg\_class</code></a>.<code>oid</code>)</p><p>The table referenced by a referential integrity constraint (zero if trigger is not for a referential integrity constraint)</p>                                                                                                              |
| <p><code>tgconstrindid</code> <code>oid</code> (references <a href="/pages/b1fii6hWVNacZFXaxWON"><code>pg\_class</code></a>.<code>oid</code>)</p><p>The index supporting a unique, primary key, referential integrity, or exclusion constraint (zero if trigger is not for one of these types of constraint)</p>                                                                                |
| <p><code>tgconstraint</code> <code>oid</code> (references <a href="/pages/Vvp4U1onn4s7t8FealAB"><code>pg\_constraint</code></a>.<code>oid</code>)</p><p>The <a href="/pages/Vvp4U1onn4s7t8FealAB"><code>pg\_constraint</code></a> entry associated with the trigger (zero if trigger is not for a constraint)</p>                                                                               |
| <p><code>tgdeferrable</code> <code>bool</code></p><p>True if constraint trigger is deferrable</p>                                                                                                                                                                                                                                                                                               |
| <p><code>tginitdeferred</code> <code>bool</code></p><p>True if constraint trigger is initially deferred</p>                                                                                                                                                                                                                                                                                     |
| <p><code>tgnargs</code> <code>int2</code></p><p>Number of argument strings passed to trigger function</p>                                                                                                                                                                                                                                                                                       |
| <p><code>tgattr</code> <code>int2vector</code> (references <a href="/pages/VopJygmvPNyHGB2zfl0Z"><code>pg\_attribute</code></a>.<code>attnum</code>)</p><p>Column numbers, if trigger is column-specific; otherwise an empty array</p>                                                                                                                                                          |
| <p><code>tgargs</code> <code>bytea</code></p><p>Argument strings to pass to trigger, each NULL-terminated</p>                                                                                                                                                                                                                                                                                   |
| <p><code>tgqual</code> <code>pg\_node\_tree</code></p><p>Expression tree (in <code>nodeToString()</code> representation) for the trigger's <code>WHEN</code> condition, or null if none</p>                                                                                                                                                                                                     |
| <p><code>tgoldtable</code> <code>name</code></p><p><code>REFERENCING</code> clause name for <code>OLD TABLE</code>, or null if none</p>                                                                                                                                                                                                                                                         |
| <p><code>tgnewtable</code> <code>name</code></p><p><code>REFERENCING</code> clause name for <code>NEW TABLE</code>, or null if none</p>                                                                                                                                                                                                                                                         |

<br>

Currently, column-specific triggering is supported only for `UPDATE` events, and so `tgattr` is relevant only for that event type. `tgtype` might contain bits for other event types as well, but those are presumed to be table-wide regardless of what is in `tgattr`.

## Note

When `tgconstraint` is nonzero, `tgconstrrelid`, `tgconstrindid`, `tgdeferrable`, and `tginitdeferred` are largely redundant with the referenced [`pg_constraint`](/internals/catalogs/catalog-pg-constraint.md) entry. However, it is possible for a non-deferrable trigger to be associated with a deferrable constraint: foreign key constraints can have some deferrable and some non-deferrable triggers.

## Note

`pg_class.relhastriggers` must be true if a relation has any triggers in this catalog.

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/catalog-pg-trigger.html)（英文原文，待翻譯）


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.postgresql.tw/internals/catalogs/catalog-pg-trigger.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
