↑↓ select↵ open⌫ change scopeOpen full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Wiki / System Catalogs

pg_type

The catalog pg_type stores information about data types. Base types and enum types (scalar types) are created with CREATE TYPE, and domains with CREATE DOMAIN. 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.

English manual coverage begins with PostgreSQL 7.4. Source history and runtime observations have their own recorded version boundaries.

Reading PG 18·Select a recorded version

kind
catalog
lang
en
measured attributes
true
metadata release
18.6
runtime verified
false
source
english-manual

Definition PG 18

The catalog pg_type stores information about data types. Base types and enum types (scalar types) are created with CREATE TYPE, and domains with CREATE DOMAIN. 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.

Catalog columns

ColumnTypeNullabilityDescription
oidoidNot nullRow identifier
typnamenameNot nullData type name
typnamespaceoidNot nullThe OID of the namespace that contains this type
typowneroidNot nullOwner of the type
typlenint2Not nullFor a fixed-size type, typlen is the number of bytes in the internal representation of the type. But for a variable-length type, typlen is negative. -1 indicates a “varlena” type (one that has a length word), -2 indicates a null-terminated C string.
typbyvalboolNot nulltypbyval 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.
typtypecharNot nulltyptype is b for a base type, c for a composite type (e.g., a table's row type), d for a domain, e for an enum type, p for a pseudo-type, r for a range type, or m for a multirange type. See also typrelid and typbasetype.
typcategorycharNot nulltypcategory is an arbitrary classification of data types that is used by the parser to determine which implicit casts should be “preferred”. See Table 52.65.
typispreferredboolNot nullTrue if the type is a preferred cast target within its typcategory
typisdefinedboolNot nullTrue if the type is defined, false if this is a placeholder entry for a not-yet-defined type. When typisdefined is false, nothing except the type name, namespace, and OID can be relied on.
typdelimcharNot nullCharacter 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.
typrelidoidNot nullIf this is a composite type (see typtype), then this column 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.
typsubscriptregprocNot nullSubscripting handler function's OID, or zero if this type doesn't support subscripting. Types that are “true” array types have typsubscript = array_subscript_handler, but other types may have other handler functions to implement specialized subscripting behavior.
typelemoidNot nullIf typelem is not zero then it identifies another row in pg_type, defining the type yielded by subscripting. This should be zero if typsubscript is zero. However, it can be zero when typsubscript isn't zero, if the handler doesn't need typelem to determine the subscripting result type. Note that a typelem 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.
typarrayoidNot nullIf typarray is not zero then it identifies another row in pg_type, which is the “true” array type having this type as element
typinputregprocNot nullInput conversion function (text format)
typoutputregprocNot nullOutput conversion function (text format)
typreceiveregprocNot nullInput conversion function (binary format), or zero if none
typsendregprocNot nullOutput conversion function (binary format), or zero if none
typmodinregprocNot nullType modifier input function, or zero if type does not support modifiers
typmodoutregprocNot nullType modifier output function, or zero to use the standard format
typanalyzeregprocNot nullCustom ANALYZE function, or zero to use the standard function
typaligncharNot nulltypalign 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: c = char alignment, i.e., 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, but by no means all).
typstoragecharNot nulltypstorage tells for varlena types (those with typlen = -1) if the type is prepared for toasting and what the default strategy for attributes of this type should be. Possible values are: p (plain): Values must always be stored plain (non-varlena types always use this value). e (external): Values can be stored in a secondary “TOAST” relation (if 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-able types. Note that m values can also be moved out to secondary storage, but only as a last resort (e and x values are moved first).
typnotnullboolNot nulltypnotnull represents a not-null constraint on a type. Used for domains only.
typbasetypeoidNot nullIf this is a domain (see typtype), then typbasetype identifies the type that this one is based on. Zero if this type is not a domain.
typtypmodint4Not nullDomains use typtypmod to record the typmod to be applied to their base type (-1 if base type does not use a typmod). -1 if this type is not a domain.
typndimsint4Not nulltypndims is the number of array dimensions for a domain over an array (that is, typbasetype is an array type). Zero for types other than domains over array types.
typcollationoidNot nulltypcollation 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 DEFAULT_COLLATION_OID. A domain over a collatable type can have a collation OID different from its base type's, if one was specified for the domain.
typdefaultbinpg_node_treeNullableIf typdefaultbin is not null, it is the nodeToString() representation of a default expression for the type. This is only used for domains.
typdefaulttextNullabletypdefault is 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 represented by typdefaultbin. If typdefaultbin is null and typdefault is not, then 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.
typaclaclitem[]NullableAccess privileges; see Section 5.8 for details

Compare versions

Complete source facts

runtime columns

oid, typname, typnamespace, typowner, typlen, typbyval, typtype, typcategory, typispreferred, typisdefined, typdelim, typrelid, typsubscript, typelem, typarray, typinput, typoutput, typreceive, typsend, typmodin, typmodout, typanalyze, typalign, typstorage, typnotnull, typbasetype, typtypmod, typndims, typcollation, typdefaultbin, typdefault, typacl

Source references

Full definition and evidence JSON

Definition sources

center · PostgreSQL 18 · catalog-bilingual-repair:5c4f11583751d53c3644ac131252146bc75665e88d6b7350c34371b4147b616d

Text language: en · catalog-bilingual-repair:5c4f11583751d53c3644ac131252146bc75665e88d6b7350c34371b4147b616d