> 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-constraint.md).

# 52.13. pg\_constraint \#

The catalog `pg_constraint` stores check, not-null, primary key, unique, foreign key, and exclusion constraints on tables. (Column constraints are not treated specially. Every column constraint is equivalent to some table constraint.)

User-defined constraint triggers (created with [`CREATE CONSTRAINT TRIGGER`](/reference/sql-commands/sql-createtrigger.md)) also give rise to an entry in this table.

Check constraints on domains are stored here, too.

**Table 52.13. `pg_constraint` Columns**

| <p>Column Type</p><p>Description</p>                                                                                                                                                                                                                                                                                                                    |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><code>oid</code> <code>oid</code></p><p>Row identifier</p>                                                                                                                                                                                                                                                                                           |
| <p><code>conname</code> <code>name</code></p><p>Constraint name (not necessarily unique!)</p>                                                                                                                                                                                                                                                           |
| <p><code>connamespace</code> <code>oid</code> (references <a href="/pages/p7uH9oRd2ZTbQCzy1qKB"><code>pg\_namespace</code></a>.<code>oid</code>)</p><p>The OID of the namespace that contains this constraint</p>                                                                                                                                       |
| <p><code>contype</code> <code>char</code></p><p><code>c</code> = check constraint, <code>f</code> = foreign key constraint, <code>n</code> = not-null constraint, <code>p</code> = primary key constraint, <code>u</code> = unique constraint, <code>t</code> = constraint trigger, <code>x</code> = exclusion constraint</p>                           |
| <p><code>condeferrable</code> <code>bool</code></p><p>Is the constraint deferrable?</p>                                                                                                                                                                                                                                                                 |
| <p><code>condeferred</code> <code>bool</code></p><p>Is the constraint deferred by default?</p>                                                                                                                                                                                                                                                          |
| <p><code>conenforced</code> <code>bool</code></p><p>Is the constraint enforced?</p>                                                                                                                                                                                                                                                                     |
| <p><code>convalidated</code> <code>bool</code></p><p>Has the constraint been validated?</p>                                                                                                                                                                                                                                                             |
| <p><code>conrelid</code> <code>oid</code> (references <a href="/pages/b1fii6hWVNacZFXaxWON"><code>pg\_class</code></a>.<code>oid</code>)</p><p>The table this constraint is on; zero if not a table constraint</p>                                                                                                                                      |
| <p><code>contypid</code> <code>oid</code> (references <a href="/pages/Rnbzy6x669U98OjJh3D7"><code>pg\_type</code></a>.<code>oid</code>)</p><p>The domain this constraint is on; zero if not a domain constraint</p>                                                                                                                                     |
| <p><code>conindid</code> <code>oid</code> (references <a href="/pages/b1fii6hWVNacZFXaxWON"><code>pg\_class</code></a>.<code>oid</code>)</p><p>The index supporting this constraint, if it's a unique, primary key, foreign key, or exclusion constraint; else zero</p>                                                                                 |
| <p><code>conparentid</code> <code>oid</code> (references <a href="/pages/Vvp4U1onn4s7t8FealAB"><code>pg\_constraint</code></a>.<code>oid</code>)</p><p>The corresponding constraint of the parent partitioned table, if this is a constraint on a partition; else zero</p>                                                                              |
| <p><code>confrelid</code> <code>oid</code> (references <a href="/pages/b1fii6hWVNacZFXaxWON"><code>pg\_class</code></a>.<code>oid</code>)</p><p>If a foreign key, the referenced table; else zero</p>                                                                                                                                                   |
| <p><code>confupdtype</code> <code>char</code></p><p>Foreign key update action code: <code>a</code> = no action, <code>r</code> = restrict, <code>c</code> = cascade, <code>n</code> = set null, <code>d</code> = set default</p>                                                                                                                        |
| <p><code>confdeltype</code> <code>char</code></p><p>Foreign key deletion action code: <code>a</code> = no action, <code>r</code> = restrict, <code>c</code> = cascade, <code>n</code> = set null, <code>d</code> = set default</p>                                                                                                                      |
| <p><code>confmatchtype</code> <code>char</code></p><p>Foreign key match type: <code>f</code> = full, <code>p</code> = partial, <code>s</code> = simple</p>                                                                                                                                                                                              |
| <p><code>conislocal</code> <code>bool</code></p><p>This constraint is defined locally for the relation. Note that a constraint can be locally defined and inherited simultaneously.</p>                                                                                                                                                                 |
| <p><code>coninhcount</code> <code>int2</code></p><p>The number of direct inheritance ancestors this constraint has. A constraint with a nonzero number of ancestors cannot be dropped nor renamed.</p>                                                                                                                                                  |
| <p><code>connoinherit</code> <code>bool</code></p><p>This constraint is defined locally for the relation. It is a non-inheritable constraint.</p>                                                                                                                                                                                                       |
| <p><code>conperiod</code> <code>bool</code></p><p>This constraint is defined with <code>WITHOUT OVERLAPS</code> (for primary keys and unique constraints) or <code>PERIOD</code> (for foreign keys).</p>                                                                                                                                                |
| <p><code>conkey</code> <code>int2\[]</code> (references <a href="/pages/VopJygmvPNyHGB2zfl0Z"><code>pg\_attribute</code></a>.<code>attnum</code>)</p><p>If a table constraint (including foreign keys, but not constraint triggers), list of the constrained columns</p>                                                                                |
| <p><code>confkey</code> <code>int2\[]</code> (references <a href="/pages/VopJygmvPNyHGB2zfl0Z"><code>pg\_attribute</code></a>.<code>attnum</code>)</p><p>If a foreign key, list of the referenced columns</p>                                                                                                                                           |
| <p><code>conpfeqop</code> <code>oid\[]</code> (references <a href="/pages/gJEllT61m6FTxxJgK6D0"><code>pg\_operator</code></a>.<code>oid</code>)</p><p>If a foreign key, list of the equality operators for PK = FK comparisons</p>                                                                                                                      |
| <p><code>conppeqop</code> <code>oid\[]</code> (references <a href="/pages/gJEllT61m6FTxxJgK6D0"><code>pg\_operator</code></a>.<code>oid</code>)</p><p>If a foreign key, list of the equality operators for PK = PK comparisons</p>                                                                                                                      |
| <p><code>conffeqop</code> <code>oid\[]</code> (references <a href="/pages/gJEllT61m6FTxxJgK6D0"><code>pg\_operator</code></a>.<code>oid</code>)</p><p>If a foreign key, list of the equality operators for FK = FK comparisons</p>                                                                                                                      |
| <p><code>confdelsetcols</code> <code>int2\[]</code> (references <a href="/pages/VopJygmvPNyHGB2zfl0Z"><code>pg\_attribute</code></a>.<code>attnum</code>)</p><p>If a foreign key with a <code>SET NULL</code> or <code>SET DEFAULT</code> delete action, the columns that will be updated. If null, all of the referencing columns will be updated.</p> |
| <p><code>conexclop</code> <code>oid\[]</code> (references <a href="/pages/gJEllT61m6FTxxJgK6D0"><code>pg\_operator</code></a>.<code>oid</code>)</p><p>If an exclusion constraint or <code>WITHOUT OVERLAPS</code> primary key/unique constraint, list of the per-column exclusion operators.</p>                                                        |
| <p><code>conbin</code> <code>pg\_node\_tree</code></p><p>If a check constraint, an internal representation of the expression. (It's recommended to use <code>pg\_get\_constraintdef()</code> to extract the definition of a check constraint.)</p>                                                                                                      |

<br>

In the case of an exclusion constraint, `conkey` is only useful for constraint elements that are simple column references. For other cases, a zero appears in `conkey` and the associated index must be consulted to discover the expression that is constrained. (`conkey` thus has the same contents as [`pg_index`](/internals/catalogs/catalog-pg-index.md).`indkey` for the index.)

## Note

`pg_class.relchecks` needs to agree with the number of check-constraint entries found in this table for each relation.

***

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