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

# 52.13. pg\_constraint \#

### 52.13. `pg_constraint` [#](#catalog-pg-constraint) <a href="#catalog-pg-constraint" id="catalog-pg-constraint"></a>

目錄 `pg_constraint` 儲存資料表上的檢查、非空值、 主鍵、唯一、外鍵與排除限制條件。 （欄位限制條件不會被特別處理。每個欄位限制條件都 等同於某個資料表限制條件。）

使用者定義的限制條件觸發程序（以 [`CREATE CONSTRAINT TRIGGER`](https://docs.postgresql.tw/19/reference/sql-commands/sql-createtrigger.md) 建立）也會在此資料表中產生一筆項目。

網域上的檢查限制條件也儲存在這裡。

#### 表 52.13. `pg_constraint` 欄位 [#](#catalog-pg-constraint-columns) <a href="#catalog-pg-constraint-columns" id="catalog-pg-constraint-columns"></a>

| <p>欄位類型</p><p>說明</p>                                                                                                                                                                                                                                                                                   |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><code>oid</code> <code>oid</code></p><p>資料列識別碼</p>                                                                                                                                                                                                                                                  |
| <p><code>conname</code> <code>name</code></p><p>限制條件名稱（不一定唯一！）</p>                                                                                                                                                                                                                                     |
| <p><code>connamespace</code> <code>oid</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-namespace.md"><code>pg\_namespace</code></a>.<code>oid</code>）</p><p>包含此限制條件之命名空間的 OID</p>                                                                                      |
| <p><code>contype</code> <code>char</code></p><p><code>c</code> = 檢查限制條件， <code>f</code> = 外鍵限制條件， <code>n</code> = 非空值限制條件， <code>p</code> = 主鍵限制條件， <code>u</code> = 唯一限制條件， <code>t</code> = 限制條件觸發程序， <code>x</code> = 排除限制條件</p>                                                                   |
| <p><code>condeferrable</code> <code>bool</code></p><p>此限制條件是否可延遲？</p>                                                                                                                                                                                                                                  |
| <p><code>condeferred</code> <code>bool</code></p><p>此限制條件是否預設為延遲？</p>                                                                                                                                                                                                                                  |
| <p><code>conenforced</code> <code>bool</code></p><p>此限制條件是否強制執行？</p>                                                                                                                                                                                                                                   |
| <p><code>convalidated</code> <code>bool</code></p><p>此限制條件是否已驗證？</p>                                                                                                                                                                                                                                   |
| <p><code>conrelid</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>contypid</code> <code>oid</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-type.md"><code>pg\_type</code></a>.<code>oid</code>）</p><p>此限制條件所在的網域；若不是網域限制條件則為零</p>                                                                                              |
| <p><code>conindid</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>conparentid</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>若此為分割區上的限制條件，則為上層分割資料表中 對應的限制條件；否則為零</p>                                                                  |
| <p><code>confrelid</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>confupdtype</code> <code>char</code></p><p>外鍵更新動作代碼： <code>a</code> = 無動作（NO ACTION）， <code>r</code> = 限制（RESTRICT）， <code>c</code> = 串聯（CASCADE）， <code>n</code> = 設為 NULL（SET NULL）， <code>d</code> = 設為預設值（SET DEFAULT）</p>                                                                |
| <p><code>confdeltype</code> <code>char</code></p><p>外鍵刪除動作代碼： <code>a</code> = 無動作（NO ACTION）， <code>r</code> = 限制（RESTRICT）， <code>c</code> = 串聯（CASCADE）， <code>n</code> = 設為 NULL（SET NULL）， <code>d</code> = 設為預設值（SET DEFAULT）</p>                                                                |
| <p><code>confmatchtype</code> <code>char</code></p><p>外鍵比對類型： <code>f</code> = 完全（FULL）， <code>p</code> = 部分（PARTIAL）， <code>s</code> = 簡單（SIMPLE）</p>                                                                                                                                                 |
| <p><code>conislocal</code> <code>bool</code></p><p>此限制條件是在該關聯上本地定義的。請注意，一個 限制條件可以同時是本地定義且繼承而來的。</p>                                                                                                                                                                                                    |
| <p><code>coninhcount</code> <code>int2</code></p><p>此限制條件擁有的直接繼承祖先數。 祖先數不為零的 限制條件既不能被移除，也不能被重新命名。</p>                                                                                                                                                                                                  |
| <p><code>connoinherit</code> <code>bool</code></p><p>此限制條件是在該關聯上本地定義的。它是一個 不可繼承的限制條件。</p>                                                                                                                                                                                                              |
| <p><code>conperiod</code> <code>bool</code></p><p>此限制條件是以 <code>WITHOUT OVERLAPS</code> （用於主鍵與唯一限制條件）或 <code>PERIOD</code> （用於外鍵）定義的。</p>                                                                                                                                                              |
| <p><code>conkey</code> <code>int2\[]</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>confkey</code> <code>int2\[]</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>conpfeqop</code> <code>oid\[]</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-operator.md"><code>pg\_operator</code></a>.<code>oid</code>）</p><p>若為外鍵，則為用於 PK = FK 比較的相等運算子清單</p>                                                                             |
| <p><code>conppeqop</code> <code>oid\[]</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-operator.md"><code>pg\_operator</code></a>.<code>oid</code>）</p><p>若為外鍵，則為用於 PK = PK 比較的相等運算子清單</p>                                                                             |
| <p><code>conffeqop</code> <code>oid\[]</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-operator.md"><code>pg\_operator</code></a>.<code>oid</code>）</p><p>若為外鍵，則為用於 FK = FK 比較的相等運算子清單</p>                                                                             |
| <p><code>confdelsetcols</code> <code>int2\[]</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-attribute.md"><code>pg\_attribute</code></a>.<code>attnum</code>）</p><p>若為刪除動作是 <code>SET NULL</code> 或 <code>SET DEFAULT</code> 的外鍵，則為將被更新的欄位。 若為 null，則所有參照欄位都會被更新。</p> |
| <p><code>conexclop</code> <code>oid\[]</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-operator.md"><code>pg\_operator</code></a>.<code>oid</code>）</p><p>若為排除限制條件或 <code>WITHOUT OVERLAPS</code> 主鍵／唯一限制條件，則為各欄位的排除運算子清單。</p>                                         |
| <p><code>conbin</code> <code>pg\_node\_tree</code></p><p>若為檢查限制條件，則為該運算式的內部表示形式。 （建議使用 <code>pg\_get\_constraintdef()</code> 來擷取 檢查限制條件的定義。）</p>                                                                                                                                                       |

<br>

對於排除限制條件，`conkey` 只對屬於簡單欄位參照的限制條件元素有用。 其他情況下，`conkey` 中會出現零， 必須查閱相關聯的索引，才能找出受限制的 運算式。（因此 `conkey` 的內容與該索引的 [`pg_index`](https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-index.md).`indkey` 相同。）

#### 注意

`pg_class.relchecks` 需要與此資料表中 針對每個關聯所找到的檢查限制條件項目數 一致。

***

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