The pg_type catalog stores information about data types.
Base types and enum types (scalar types) are created with
CREATE TYPE.Domains are created with
CREATE DOMAIN.A composite type is automatically created for each table in the database to represent the row structure of that table. You can also create composite types with
CREATE TYPE AS.
Columns
| Column | Type | Description |
|---|---|---|
oid | oid | Row identifier. |
typname | name | Data type name. |
typnamespace | oid | OID of the namespace that contains this type. |
typowner | oid | Owner of the type. |
typlen | int2 | For fixed-size types, the number of bytes in the internal representation. For variable-length types, a negative value: -1 indicates a varlena type (one that has a length word); -2 indicates a null-terminated C string. |
typbyval | bool | Determines whether internal routines pass a value of this type by value or by reference. typbyval had better be false if typlen 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 typbyval can be false even if the length would allow pass-by-value. |
typtype | char | The kind of type. See typtype values. |
typcategory | char | An arbitrary classification used by the parser to determine which implicit casts should be preferred. See typcategory codes. |
typispreferred | bool | true if this type is a preferred cast target within its typcategory. |
typisdefined | bool | true if the type is fully defined. false if this is a placeholder entry for a not-yet-defined type — in which case, only the type name, namespace, and OID can be relied on. |
typdelim | char | The character that separates two values of this type when parsing array input. The delimiter is associated with the array element type, not the array type itself. |
typrelid | oid | For composite types, points to the pg_class entry that defines the corresponding table. (For a free-standing composite type, the pg_class entry doesn't really represent a table, but it is needed anyway for the type's pg_attribute entries to link to.) Zero for non-composite types. |
typelem | oid | If nonzero, identifies another row in pg_type that defines the type yielded by subscripting. Zero when typsubscript is zero, though it can also be zero when typsubscript is nonzero if the handler does not need typelem to determine the subscripting result type. A typelem dependency implies physical containment of the element type in this type, which may restrict DDL changes on the element type. |
typarray | oid | If nonzero, identifies another row in pg_type that is the "true" array type having this type as its element type. |
typinput | regproc | Input conversion function (text format). |
typoutput | regproc | Output conversion function (text format). |
typreceive | regproc | Input conversion function (binary format), or zero if none. |
typsend | regproc | Output conversion function (binary format), or zero if none. |
typmodin | regproc | Type modifier input function, or zero if the type does not support modifiers. |
typmodout | regproc | Type modifier output function, or zero to use the standard format. |
typanalyze | regproc | Custom ANALYZE function, or zero to use the standard function. |
typalign | char | The alignment required when storing a value of this type. Applies to disk storage and most in-memory representations. When multiple values are stored consecutively (for example, in a complete row on disk), padding is inserted before a value of this type so that it begins on the specified boundary, measured from the start of the first datum in the sequence. Possible values: c = char alignment (no alignment needed); s = short alignment (2 bytes on most machines); i = int alignment (4 bytes on most machines); d = double alignment (8 bytes on many machines). |
typstorage | char | For varlena types (typlen = -1), indicates whether the type supports TOAST (The Oversized-Attribute Storage Technique) and what the default storage strategy is for columns of this type. Possible values: p (plain) = values must always be stored without compression or out-of-line storage; e (external) = values can be stored in a secondary TOAST relation (if the relation has one, see pg_class.reltoastrelid); m (main) = values can be compressed and stored inline; x (extended) = values can be compressed and/or moved to a secondary relation. x is the usual choice for TOAST-capable types. m values can also be moved to secondary storage, but only as a last resort (e and x values are moved first). Non-varlena types always use p. |
typnotnull | bool | Represents a NOT NULL constraint on the type. Used for domains only. |
typbasetype | oid | For domains, identifies the base type. Zero for non-domain types. |
typtypmod | int4 | For domains, records the type modifier (typmod) applied to the base type. -1 if the base type does not use a type modifier, or if this type is not a domain. |
typndims | int4 | Number of array dimensions for a domain over an array type (that is, typbasetype is an array type). Zero for types other than array domains. |
typcollation | oid | The collation of the type. Zero if the type does not support collations. A base type that supports collations has a nonzero value here, typically DEFAULT_COLLATION_OID. A domain over a collatable type can have a different collation OID from its base type if one was specified for the domain. |
typdefaultbin | pg_node_tree | If not null, the nodeToString() representation of a default expression for the type. Used only for domains. |
typdefault | text | Null if the type has no associated default value. If typdefaultbin is not null, typdefault must contain a human-readable version of the default expression in typdefaultbin. If typdefaultbin is null and typdefault is not null, typdefault is the external representation of the type's default value, which can be fed to the type's input converter to produce a constant. |
typacl | aclitem[] | Access privileges. |
Note
For fixed-width types used in system tables, the size and alignment defined in pg_type must agree with the way the compiler lays out the column in a structure representing a table row.
typtype values
| Value | Type |
|---|---|
b | Base type |
c | Composite type (for example, a table's row type) |
d | Domain |
e | Enum type |
p | Pseudo-type |
r | Range type |
typcategory codes
The typcategory column uses single uppercase ASCII letters. Future system-defined categories will also use uppercase ASCII letters. All other ASCII characters are reserved for user-defined categories.
| 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 |