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

# 52.64. pg\_type \#

The catalog `pg_type` stores information about data types. Base types and enum types (scalar types) are created with [`CREATE TYPE`](/reference/sql-commands/sql-createtype.md), and domains with [`CREATE DOMAIN`](/reference/sql-commands/sql-createdomain.md). A composite type is automatically created for each table in the database, to represent the row structure of the table. It is also possible to create composite types with `CREATE TYPE AS`.

**Table 52.64. `pg_type` Columns**

| <p>Column Type</p><p>Description</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><code>oid</code> <code>oid</code></p><p>Row identifier</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| <p><code>typname</code> <code>name</code></p><p>Data type name</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| <p><code>typnamespace</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 type</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| <p><code>typowner</code> <code>oid</code> (references <a href="/pages/nyEMOe5gQKgypFQTDbjS"><code>pg\_authid</code></a>.<code>oid</code>)</p><p>Owner of the type</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| <p><code>typlen</code> <code>int2</code></p><p>For a fixed-size type, <code>typlen</code> is the number of bytes in the internal representation of the type. But for a variable-length type, <code>typlen</code> is negative. -1 indicates a “varlena” type (one that has a length word), -2 indicates a null-terminated C string.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| <p><code>typbyval</code> <code>bool</code></p><p><code>typbyval</code> determines whether internal routines pass a value of this type by value or by reference. <code>typbyval</code> had better be false if <code>typlen</code> is not 1, 2, or 4 (or 8 on machines where Datum is 8 bytes). Variable-length types are always passed by reference. Note that <code>typbyval</code> can be false even if the length would allow pass-by-value.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| <p><code>typtype</code> <code>char</code></p><p><code>typtype</code> is <code>b</code> for a base type, <code>c</code> for a composite type (e.g., a table's row type), <code>d</code> for a domain, <code>e</code> for an enum type, <code>p</code> for a pseudo-type, <code>r</code> for a range type, or <code>m</code> for a multirange type. See also <code>typrelid</code> and <code>typbasetype</code>.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| <p><code>typcategory</code> <code>char</code></p><p><code>typcategory</code> is an arbitrary classification of data types that is used by the parser to determine which implicit casts should be “preferred”. See <a href="#CATALOG-TYPCATEGORY-TABLE">Table 52.65</a>.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| <p><code>typispreferred</code> <code>bool</code></p><p>True if the type is a preferred cast target within its <code>typcategory</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| <p><code>typisdefined</code> <code>bool</code></p><p>True if the type is defined, false if this is a placeholder entry for a not-yet-defined type. When <code>typisdefined</code> is false, nothing except the type name, namespace, and OID can be relied on.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| <p><code>typdelim</code> <code>char</code></p><p>Character that separates two values of this type when parsing array input. Note that the delimiter is associated with the array element data type, not the array data type.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| <p><code>typrelid</code> <code>oid</code> (references <a href="/pages/b1fii6hWVNacZFXaxWON"><code>pg\_class</code></a>.<code>oid</code>)</p><p>If this is a composite type (see <code>typtype</code>), then this column points to the <a href="/pages/b1fii6hWVNacZFXaxWON"><code>pg\_class</code></a> entry that defines the corresponding table. (For a free-standing composite type, the <a href="/pages/b1fii6hWVNacZFXaxWON"><code>pg\_class</code></a> entry doesn't really represent a table, but it is needed anyway for the type's <a href="/pages/VopJygmvPNyHGB2zfl0Z"><code>pg\_attribute</code></a> entries to link to.) Zero for non-composite types.</p>                                                                                                                                                                                                                                                                                                   |
| <p><code>typsubscript</code> <code>regproc</code> (references <a href="/pages/8TiLY9QeJalZY0OBAANF"><code>pg\_proc</code></a>.<code>oid</code>)</p><p>Subscripting handler function's OID, or zero if this type doesn't support subscripting. Types that are “true” array types have <code>typsubscript</code> = <code>array\_subscript\_handler</code>, but other types may have other handler functions to implement specialized subscripting behavior.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| <p><code>typelem</code> <code>oid</code> (references <a href="/pages/Rnbzy6x669U98OjJh3D7"><code>pg\_type</code></a>.<code>oid</code>)</p><p>If <code>typelem</code> is not zero then it identifies another row in <code>pg\_type</code>, defining the type yielded by subscripting. This should be zero if <code>typsubscript</code> is zero. However, it can be zero when <code>typsubscript</code> isn't zero, if the handler doesn't need <code>typelem</code> to determine the subscripting result type. Note that a <code>typelem</code> dependency is considered to imply physical containment of the element type in this type; so DDL changes on the element type might be restricted by the presence of this type.</p>                                                                                                                                                                                                                                          |
| <p><code>typarray</code> <code>oid</code> (references <a href="/pages/Rnbzy6x669U98OjJh3D7"><code>pg\_type</code></a>.<code>oid</code>)</p><p>If <code>typarray</code> is not zero then it identifies another row in <code>pg\_type</code>, which is the “true” array type having this type as element</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| <p><code>typinput</code> <code>regproc</code> (references <a href="/pages/8TiLY9QeJalZY0OBAANF"><code>pg\_proc</code></a>.<code>oid</code>)</p><p>Input conversion function (text format)</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| <p><code>typoutput</code> <code>regproc</code> (references <a href="/pages/8TiLY9QeJalZY0OBAANF"><code>pg\_proc</code></a>.<code>oid</code>)</p><p>Output conversion function (text format)</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| <p><code>typreceive</code> <code>regproc</code> (references <a href="/pages/8TiLY9QeJalZY0OBAANF"><code>pg\_proc</code></a>.<code>oid</code>)</p><p>Input conversion function (binary format), or zero if none</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| <p><code>typsend</code> <code>regproc</code> (references <a href="/pages/8TiLY9QeJalZY0OBAANF"><code>pg\_proc</code></a>.<code>oid</code>)</p><p>Output conversion function (binary format), or zero if none</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| <p><code>typmodin</code> <code>regproc</code> (references <a href="/pages/8TiLY9QeJalZY0OBAANF"><code>pg\_proc</code></a>.<code>oid</code>)</p><p>Type modifier input function, or zero if type does not support modifiers</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| <p><code>typmodout</code> <code>regproc</code> (references <a href="/pages/8TiLY9QeJalZY0OBAANF"><code>pg\_proc</code></a>.<code>oid</code>)</p><p>Type modifier output function, or zero to use the standard format</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| <p><code>typanalyze</code> <code>regproc</code> (references <a href="/pages/8TiLY9QeJalZY0OBAANF"><code>pg\_proc</code></a>.<code>oid</code>)</p><p>Custom <a href="/pages/-LBxTh9Zm5_YS7bTGgfk">ANALYZE</a> function, or zero to use the standard function</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| <p><code>typalign</code> <code>char</code></p><p><code>typalign</code> is the alignment required when storing a value of this type. It applies to storage on disk as well as most representations of the value inside PostgreSQL. When multiple values are stored consecutively, such as in the representation of a complete row on disk, padding is inserted before a datum of this type so that it begins on the specified boundary. The alignment reference is the beginning of the first datum in the sequence. Possible values are:</p><ul><li><code>c</code> = <code>char</code> alignment, i.e., no alignment needed.</li><li><code>s</code> = <code>short</code> alignment (2 bytes on most machines).</li><li><code>i</code> = <code>int</code> alignment (4 bytes on most machines).</li><li><code>d</code> = <code>double</code> alignment (8 bytes on many machines, but by no means all).</li></ul>                                                          |
| <p><code>typstorage</code> <code>char</code></p><p><code>typstorage</code> tells for varlena types (those with <code>typlen</code> = -1) if the type is prepared for toasting and what the default strategy for attributes of this type should be. Possible values are:</p><ul><li><code>p</code> (plain): Values must always be stored plain (non-varlena types always use this value).</li><li><code>e</code> (external): Values can be stored in a secondary “TOAST” relation (if relation has one, see <code>pg\_class.reltoastrelid</code>).</li><li><code>m</code> (main): Values can be compressed and stored inline.</li><li><code>x</code> (extended): Values can be compressed and/or moved to a secondary relation.</li></ul><p><code>x</code> is the usual choice for toast-able types. Note that <code>m</code> values can also be moved out to secondary storage, but only as a last resort (<code>e</code> and <code>x</code> values are moved first).</p> |
| <p><code>typnotnull</code> <code>bool</code></p><p><code>typnotnull</code> represents a not-null constraint on a type. Used for domains only.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| <p><code>typbasetype</code> <code>oid</code> (references <a href="/pages/Rnbzy6x669U98OjJh3D7"><code>pg\_type</code></a>.<code>oid</code>)</p><p>If this is a domain (see <code>typtype</code>), then <code>typbasetype</code> identifies the type that this one is based on. Zero if this type is not a domain.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| <p><code>typtypmod</code> <code>int4</code></p><p>Domains use <code>typtypmod</code> to record the <code>typmod</code> to be applied to their base type (-1 if base type does not use a <code>typmod</code>). -1 if this type is not a domain.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| <p><code>typndims</code> <code>int4</code></p><p><code>typndims</code> is the number of array dimensions for a domain over an array (that is, <code>typbasetype</code> is an array type). Zero for types other than domains over array types.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| <p><code>typcollation</code> <code>oid</code> (references <a href="/pages/NXiMpFyxCVHCoDPqdrtW"><code>pg\_collation</code></a>.<code>oid</code>)</p><p><code>typcollation</code> specifies the collation of the type. If the type does not support collations, this will be zero. A base type that supports collations will have a nonzero value here, typically <code>DEFAULT\_COLLATION\_OID</code>. A domain over a collatable type can have a collation OID different from its base type's, if one was specified for the domain.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| <p><code>typdefaultbin</code> <code>pg\_node\_tree</code></p><p>If <code>typdefaultbin</code> is not null, it is the <code>nodeToString()</code> representation of a default expression for the type. This is only used for domains.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| <p><code>typdefault</code> <code>text</code></p><p><code>typdefault</code> is null if the type has no associated default value. If <code>typdefaultbin</code> is not null, <code>typdefault</code> must contain a human-readable version of the default expression represented by <code>typdefaultbin</code>. If <code>typdefaultbin</code> is null and <code>typdefault</code> is not, then <code>typdefault</code> is the external representation of the type's default value, which can be fed to the type's input converter to produce a constant.</p>                                                                                                                                                                                                                                                                                                                                                                                                                |
| <p><code>typacl</code> <code>aclitem\[]</code></p><p>Access privileges; see <a href="/pages/VX212noXJkZ6WiwCHQE7">Section 5.8</a> for details</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |

<br>

## Note

For fixed-width types used in system tables, it is critical that the size and alignment defined in `pg_type` agree with the way that the compiler will lay out the column in a structure representing a table row.

[Table 52.65](#CATALOG-TYPCATEGORY-TABLE) lists the system-defined values of `typcategory`. Any future additions to this list will also be upper-case ASCII letters. All other ASCII characters are reserved for user-defined categories.

**Table 52.65. `typcategory` Codes**

| Code | Category              |
| ---- | --------------------- |
| `A`  | Array types           |
| `B`  | Boolean types         |
| `C`  | Composite types       |
| `D`  | Date/time types       |
| `E`  | Enum types            |
| `G`  | Geometric types       |
| `I`  | Network address types |
| `N`  | Numeric types         |
| `P`  | Pseudo-types          |
| `R`  | Range types           |
| `S`  | String types          |
| `T`  | Timespan types        |
| `U`  | User-defined types    |
| `V`  | Bit-string types      |
| `X`  | `unknown` type        |
| `Z`  | Internal-use types    |

<br>

***

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