Updated on 2025-08-25 GMT+08:00

PG_TYPE

PG_TYPE stores information about data types.

Table 1 PG_TYPE columns

Column

Type

Description

typname

name

Name of a data type.

typnamespace

oid

OID of the namespace containing this type.

typowner

oid

Owner of the type.

typlen

smallint

For fixed-length types, this is the byte size of the internal representation. For variable-length types, this parameter value is negative. Options:

  • -1 indicates a variable-length type (with a length-word attribute).
  • -2 indicates a null-terminated C string.

typbyval

Boolean

Whether values of this type are passed by value or by reference internally. If TYPLEN of this type is not 1, 2, 4, or 8, you are advised to set TYPBYVAL to false. Variable-length types are typically passed by reference. Even if TYPLEN permits passing by value, TYPBYVAL may still be false.

typtype

"char"

  • b indicates a base type.
  • c indicates a composite type (for example, a table's row type).
  • e indicates an enumerated type.
  • p indicates a pseudo type.

See typrelid and typbasetype.

typcategory

"char"

Broad category of the data type, useful as a basis for data conversions performed by the parser.

typispreferred

Boolean

If the value is true, the data will be converted when it matches the conversion rules specified by TYPCATEGORY.

typisdefined

Boolean

If a type is defined, the value is true. The value is false if it serves as a placeholder for an undefined type. If set to false, there are no dependencies other than the type's name, namespace, and OID.

typdelim

"char"

Character separating two values of this type during array input parsing. Note that the delimiter is associated with the array element data type, not the array data type itself.

typrelid

oid

If this is a composite type (see typtype), this column points to the row in pg_class defining the table. For standalone composite types, the pg_class entry does not represent a table but is necessary to locate the pg_attribute entries linked to the type. The value is 0 for non-composite types.

typelem

oid

If the value is not 0, it identifies another row in pg_type. The current type can be treated as an array of elements of typelem. A true array type is variable-length (typlen = -1), but some fixed-length types (typlen > 0) also have a nonzero typelem (for example, name and point). If a fixed-length type has a typelem, its internal form must only consist of a specific number of elements of the typelem data type, with no additional data. Variable-length array types include a header defined by the array subroutine.

typarray

oid

If the value is not 0, there is a corresponding type record in pg_type.

typinput

regproc

Input conversion function (text format).

typoutput

regproc

Output conversion function (text format).

typreceive

regproc

Input conversion function (binary format). If there are no such functions, the value is 0.

typsend

regproc

Output conversion function (binary format). If there are no such functions, the value is 0.

typmodin

regproc

Input type modifier function. Such functions are not supported if the value is 0.

typmodout

regproc

Output type modifier function. Such functions are not supported if the value is 0.

typanalyze

regproc

Custom ANALYZE function. If standard functions are used, the value is 0.

typalign

"char"

Alignment requirement when storing values of this type. It applies to disk storage and most representations of the value in the database. If values are stored contiguously, such as in raw data on disk, padding is added before the data to meet the required boundary. The alignment reference is the start of the first data in the sequence. Options include:

  • c: char alignment, that is, 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 not necessarily all).
NOTICE:

For types used in system catalogs, the size and alignment defined in pg_type must match the layout of the compiler in the structure representing table rows.

typstorage

"char"

Whether a variable-length type (those with typlen = -1) is prepared to handle non-conventional values and what the default strategy is for this attribute's type. Options include:

  • p: Values are always stored simply.
  • e: Values can be stored in a secondary relationship (if available, see pg_class.reltoastrelid).
  • m: Values can be stored in inline compressed mode.
  • x: Values can be stored either inline compressed or in the secondary table.
NOTICE:

m domains can also be moved to the subsidiary table for storage, but only as a last resort (first move the e and x domains).

typenotnull

Boolean

A NOTNULL constraint on a certain type. Currently used only for domains.

typbasetype

oid

If this is a derived type (refer to typtype), this identifier serves as the base type for this type. The value is 0 if it is not a derived type.

typtypmod

integer

Domains use typtypmod to record the typmod to be applied to their base type (the value is -1 if the base type does not use typmod). The value is -1 if this type is not a domain.

typndims

integer

If a domain is an array, typndims indicates the number of dimensions in the array (that is, typbasetype is an array type. The typelem of the domain will match the typelem of the base type). The value is 0 for non-array types.

typcollation

oid

Collation of the type. If the value is 0, collation is not supported.

typdefaultbin

pg_node_tree

If the value is not null, it indicates the nodeToString() form of the default expression for this type. This column is currently used only for domains.

typdefault

text

If there is no related default value for the type, the value is null. If typdefaultbin is not null, typdefault must include a human-readable version of the default expression represented by typdefaultbin. If typdefaultbin is null but typdefault is not null, then typdefault is the external representation of the type's default value, which can be fed into the type's converter to produce a constant.

typacl

aclitem[]

Access permissions.