Полезная информация

3.22. pg_type

This catalog stores information about data types. Scalar types ("base types") are created with CREATE TYPE. A complex type is also created for each table in the database, to represent the row structure of the table. It is also possible to create derived types with CREATE DOMAIN.

Table 3-22. pg_type Columns

NameTypeReferencesDescription
typnamename Data type name
typownerint4pg_shadow.usesysidOwner (creator) of the type
typlenint2 Length of the storage representation of the type, -1 if variable length
typprtlenint2 unused
typbyvalbool  typbyval determines whether internal routines pass a value of this type by value or by reference. Only char, short, and int equivalent items can be passed by value, so if the type is not 1, 2, or 4 bytes long, PostgreSQL does not have the option of passing by value and so typbyval had better be false. Variable-length types are always passed by reference. Note that typbyval can be false even if the length would allow pass-by-value; this is currently true for type float4, for example.
typtypechar  typtype is b for a base type, c for a complex type (i.e., a table's row type), or d for a derived type (i.e., a domain). See also typrelid and typbasetype.
typisdefinedbool True 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 and OID can be relied on.
typdelimchar 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.
typrelidoidpg_class.oid If this is a complex type (see typtype), then this field points to the pg_class entry that defines the corresponding table. A table could theoretically be used as a composite data type, but this is not fully functional. Zero for non-complex types.
typelemoidpg_type.oid If typelem is not 0 then it identifies another row in pg_type. The current type can then be subscripted like an array yielding values of type typelem. A "true" array type is variable length (typlen = -1), but some fixed-length (typlen > 0) types also have nonzero typelem, for example name and oidvector. If a fixed-length type has a typelem then its internal representation must be N values of the typelem data type with no other data. Variable-length array types have a header defined by the array subroutines.
typinputregproc Input function
typoutputregproc Output function
typreceiveregproc unused
typsendregproc unused
typalignchar 

typalign 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).

Note: For 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 field in a struct representing a table row.

typstoragechar 

typstorage tells for variable-length 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': Value must always be stored plain.

  • 'e': Value can be stored in a "secondary" relation (if relation has one, see pg_class.reltoastrelid).

  • 'm': Value can be stored compressed inline.

  • 'x': Value can be stored compressed inline or in "secondary".

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

typnotnullbool 

typnotnull represents a NOT NULL constraint on a type. Presently used for domains only.

typbasetypeoidpg_type.oid

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

typtypmodint4 

typtypmod records type-specific data supplied at table creation time (for example, the maximum length of a varchar column). It is passed to type-specific input and output functions as the third argument. The value will generally be -1 for types that do not need typmod. This value is copied to pg_attribute.atttypmod when creating a column of a domain type.

typndimsint4 

typndims is the number of array dimensions for a domain that is an array. (The array element type is typbasetype.) Zero for non-domains and non-array domains. This value is copied to pg_attribute.attndims when creating a column of a domain type.

typdefaultbintext 

If typdefaultbin is not NULL, it is the nodeToString representation of a default expression for the type. Currently this is only used for domains.

typdefaulttext 

typdefault 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 may be fed to the type's input converter to produce a constant.