Updated on 2024-06-03 GMT+08:00

PG_TYPE

PG_TYPE stores information about data types.

Table 1 PG_TYPE columns

Name

Type

Description

oid

oid

Row identifier (hidden attribute, which must be specified).

typname

name

Data type name.

typnamespace

oid

OID of the namespace that contains the type.

typowner

oid

Owner of the type.

typlen

smallint

Number of bytes in the internal representation of the type for a fixed-size type. It is a negative number for a variable-length type.
  • The value –1 indicates a "varlena" type (one that has a length word).
  • The value –2 indicates a null-terminated C string.

typbyval

Boolean

  • true: A value of this type is transferred by value internally.
  • false: A value of this type is transferred by reference internally.

If typlen of this type is not 1, 2, 4, or 8, you are advised to transfer a reference value for typbyval. You can also transfer a value for typbyval. Variable-length types are usually passed by reference or by value.

typtype

"char"

  • b: basic type.
  • c: composite type (for example, the row type of a table).
  • d: domain type.
  • p: pseudo type.
  • u: undefined type.
  • o: set type.

For details, see typrelid and typbasetype.

typcategory

"char"

Fuzzy classification of data types, which can be used by parsers as the basis for data conversion.

typispreferred

Boolean

  • true: Data is converted when it complies with the conversion rule specified by typcategory.
  • false: Data is not converted.

typisdefined

Boolean

  • true: The type has been defined.
  • false: The placeholder of an undefined type is used. In this case, there is no reliable information except the name, namespace, and OID of the type.

typdelim

"char"

Character that separates two values of this type when parsing an array input. Note that the delimiter is associated with the array element data type, not the array data type.

typrelid

oid

If 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 does not represent a table, but it is required for the type's PG_ATTRIBUTE entries to link to. It is 0 for non-composite type.

typelem

oid

If typelem is not 0, it identifies another row in PG_TYPE. The current type can be described as an array yielding values of type typelem. A "true" array type has a variable length (typlen = –1), but some fixed-length types (typlen > 0) also have non-zero typelem, for example name and point. If a fixed-length type has a typelem, its internal representation must be a number of values of the typelem data type with no other data. Variable-length array types have a header defined by the array subroutines.

typarray

oid

If the value is not 0, the corresponding type record is available in PG_TYPE.

typinput

regproc

Input conversion function (text format)

typoutput

regproc

Output conversion function (text format)

typreceive

regproc

Input conversion function (binary format); 0 for non-input conversion function

typsend

regproc

output conversion function (binary format); 0 for non-output conversion function

typmodin

regproc

Input type modifier function; 0 if none.

typmodout

regproc

Output type modifier function; 0 if none.

typanalyze

regproc

Custom ANALYZE function; 0 if the standard function is used.

typalign

"char"

Alignment required when storing a value of this type. It applies to storage on disks as well as most representations of the value. When multiple values are stored consecutively, such as in the representation of a complete row on disk, padding is inserted before a data 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, that is, no alignment required
  • s: short alignment (2 bytes on most machines)
  • i: integer alignment (4 bytes on most machines)
  • d: double alignment (8 bytes on many machines, but by no means all)
NOTICE:

For types used in system tables, the size and alignment defined in PG_TYPE must agree with the way that the compiler lays out the column in a structure representing a table row.

typstorage

"char"

typstorage 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: Values are always stored plain.
  • e: Values can be stored in a secondary relationship (if the relation has one, see reltoastrelid in 12.2.15.28 PG_CLASS).
  • m: Values can be stored compressed inline.
  • x: Values can be stored compressed inline or stored in secondary storage.
NOTICE:

m domains can also be moved out to secondary storage, but only as a last resort (e and x domains are moved first).

typnotnull

Boolean

Specifies whether the type has a NOTNULL constraint. Currently, it is used for domains only.

typbasetype

oid

If this is a domain (see typtype), then typbasetype identifies the type that this one is based on. The value is 0 if this type is not a derived type.

typtypmod

integer

Records the typtypmod to be applied to domains' base types by domains (the value is –1 if the base type does not use typmod). This is –1 if this type is not a domain.

If the type is array, typtypmod indicates the maximum capacity of the array type.

If the type is index-by table collection, typtypmod indicates the maximum index length of the collection type.

typndims

integer

If a field is an array, typndims is the number of array dimensions. This is 0 for types other than domains over array types.

typcollation

oid

Sequence rule for specified types. For details about the value, see the system catalog in PG_COLLATION. (0 if sequencing is not supported)

typdefaultbin

pg_node_tree

nodeToString() representation of a default expression for the type if the value is non-null. Currently, this column is only used for domains.

typdefault

text

The value is NULL if a type has no associated default value.

  • If typdefaultbin is not NULL, typdefault must contain a 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.

typacl

aclitem[]

Access permission

typelemmod

integer

  • -1: typmod is not required for the element type corresponding to the set and array types.
  • Value greater than or equal to 0: typmod of the element type corresponding to the set and array types is used.
  • NULL: typmod of the element type corresponding to the set and array types is unknown.

typmod usually refers to the maximum length of a type.