52.64. pg_type
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.
Column Type Description |
|---|
oid Row identifier |
typname Data type name |
typnamespace The OID of the namespace that contains this type |
typowner Owner of the type |
typlen For 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. |
typbyval typbyval 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 typtype is |
typcategory typcategory is an arbitrary classification of data types that is used by the parser to determine which implicit casts should be "preferred". See Codes. |
typispreferred True if the type is a preferred cast target within its typcategory |
typisdefined 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, namespace, and OID can be relied on. |
typdelim 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. |
typrelid 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 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. |
typsubscript Subscripting handler function's OID, or zero if this type doesn't support subscripting. Types that are "true" array types have typsubscript = |
typelem If 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. |
typarray If typarray is not zero then it identifies another row in pg_type, which is the "true" array type having this type as element |
typinput Input conversion function (text format) |
typoutput Output conversion function (text format) |
typreceive Input conversion function (binary format), or zero if none |
typsend Output conversion function (binary format), or zero if none |
typmodin Type modifier input function, or zero if type does not support modifiers |
typmodout Type modifier output function, or zero to use the standard format |
typanalyze Custom ANALYZE function, or zero to use the standard function |
typalign 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:
|
typstorage 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:
|
typnotnull typnotnull represents a not-null constraint on a type. Used for domains only. |
typbasetype If 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. |
typtypmod Domains use typtypmod to record the |
typndims typndims 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. |
typcollation typcollation 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 |
typdefaultbin If typdefaultbin is not null, it is the |
typdefault 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 can be fed to the type's input converter to produce a constant. |
typacl Access privileges; see Privileges for details |
: pg_type Columns
For fixed-width 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 column in a structure representing a table row.
Codes lists the system-defined values of typcategory. Any future additions to this list will also be upper-case ASCII letters. All other ASCII characters are reserved for user-defined categories.
Code |
Category |
|---|---|
|
Array types |
|
Boolean types |
|
Composite types |
|
Date/time types |
|
Enum types |
|
Geometric types |
|
Network address types |
|
Numeric types |
|
Pseudo-types |
|
Range types |
|
String types |
|
Timespan types |
|
User-defined types |
|
Bit-string types |
|
|
|
Internal-use types |
: typcategory Codes