4 The catalog pg_type stores information about data types. Base types and
5 enum types (scalar types) are created with CREATE TYPE, and domains
6 with CREATE DOMAIN. A composite type is automatically created for each
7 table in the database, to represent the row structure of the table. It
8 is also possible to create composite types with CREATE TYPE AS.
10 Table 52.64. pg_type Columns
24 typnamespace oid (references pg_namespace.oid)
26 The OID of the namespace that contains this type
28 typowner oid (references pg_authid.oid)
34 For a fixed-size type, typlen is the number of bytes in the internal
35 representation of the type. But for a variable-length type, typlen is
36 negative. -1 indicates a “varlena” type (one that has a length word),
37 -2 indicates a null-terminated C string.
41 typbyval determines whether internal routines pass a value of this type
42 by value or by reference. typbyval had better be false if typlen is not
43 1, 2, or 4 (or 8 on machines where Datum is 8 bytes). Variable-length
44 types are always passed by reference. Note that typbyval can be false
45 even if the length would allow pass-by-value.
49 typtype is b for a base type, c for a composite type (e.g., a table's
50 row type), d for a domain, e for an enum type, p for a pseudo-type, r
51 for a range type, or m for a multirange type. See also typrelid and
56 typcategory is an arbitrary classification of data types that is used
57 by the parser to determine which implicit casts should be “preferred”.
62 True if the type is a preferred cast target within its typcategory
66 True if the type is defined, false if this is a placeholder entry for a
67 not-yet-defined type. When typisdefined is false, nothing except the
68 type name, namespace, and OID can be relied on.
72 Character that separates two values of this type when parsing array
73 input. Note that the delimiter is associated with the array element
74 data type, not the array data type.
76 typrelid oid (references pg_class.oid)
78 If this is a composite type (see typtype), then this column points to
79 the pg_class entry that defines the corresponding table. (For a
80 free-standing composite type, the pg_class entry doesn't really
81 represent a table, but it is needed anyway for the type's pg_attribute
82 entries to link to.) Zero for non-composite types.
84 typsubscript regproc (references pg_proc.oid)
86 Subscripting handler function's OID, or zero if this type doesn't
87 support subscripting. Types that are “true” array types have
88 typsubscript = array_subscript_handler, but other types may have other
89 handler functions to implement specialized subscripting behavior.
91 typelem oid (references pg_type.oid)
93 If typelem is not zero then it identifies another row in pg_type,
94 defining the type yielded by subscripting. This should be zero if
95 typsubscript is zero. However, it can be zero when typsubscript isn't
96 zero, if the handler doesn't need typelem to determine the subscripting
97 result type. Note that a typelem dependency is considered to imply
98 physical containment of the element type in this type; so DDL changes
99 on the element type might be restricted by the presence of this type.
101 typarray oid (references pg_type.oid)
103 If typarray is not zero then it identifies another row in pg_type,
104 which is the “true” array type having this type as element
106 typinput regproc (references pg_proc.oid)
108 Input conversion function (text format)
110 typoutput regproc (references pg_proc.oid)
112 Output conversion function (text format)
114 typreceive regproc (references pg_proc.oid)
116 Input conversion function (binary format), or zero if none
118 typsend regproc (references pg_proc.oid)
120 Output conversion function (binary format), or zero if none
122 typmodin regproc (references pg_proc.oid)
124 Type modifier input function, or zero if type does not support
127 typmodout regproc (references pg_proc.oid)
129 Type modifier output function, or zero to use the standard format
131 typanalyze regproc (references pg_proc.oid)
133 Custom ANALYZE function, or zero to use the standard function
137 typalign is the alignment required when storing a value of this type.
138 It applies to storage on disk as well as most representations of the
139 value inside PostgreSQL. When multiple values are stored consecutively,
140 such as in the representation of a complete row on disk, padding is
141 inserted before a datum of this type so that it begins on the specified
142 boundary. The alignment reference is the beginning of the first datum
143 in the sequence. Possible values are:
144 * c = char alignment, i.e., no alignment needed.
145 * s = short alignment (2 bytes on most machines).
146 * i = int alignment (4 bytes on most machines).
147 * d = double alignment (8 bytes on many machines, but by no means
152 typstorage tells for varlena types (those with typlen = -1) if the type
153 is prepared for toasting and what the default strategy for attributes
154 of this type should be. Possible values are:
155 * p (plain): Values must always be stored plain (non-varlena types
156 always use this value).
157 * e (external): Values can be stored in a secondary “TOAST” relation
158 (if relation has one, see pg_class.reltoastrelid).
159 * m (main): Values can be compressed and stored inline.
160 * x (extended): Values can be compressed and/or moved to a secondary
163 x is the usual choice for toast-able types. Note that m values can also
164 be moved out to secondary storage, but only as a last resort (e and x
165 values are moved first).
169 typnotnull represents a not-null constraint on a type. Used for domains
172 typbasetype oid (references pg_type.oid)
174 If this is a domain (see typtype), then typbasetype identifies the type
175 that this one is based on. Zero if this type is not a domain.
179 Domains use typtypmod to record the typmod to be applied to their base
180 type (-1 if base type does not use a typmod). -1 if this type is not a
185 typndims is the number of array dimensions for a domain over an array
186 (that is, typbasetype is an array type). Zero for types other than
187 domains over array types.
189 typcollation oid (references pg_collation.oid)
191 typcollation specifies the collation of the type. If the type does not
192 support collations, this will be zero. A base type that supports
193 collations will have a nonzero value here, typically
194 DEFAULT_COLLATION_OID. A domain over a collatable type can have a
195 collation OID different from its base type's, if one was specified for
198 typdefaultbin pg_node_tree
200 If typdefaultbin is not null, it is the nodeToString() representation
201 of a default expression for the type. This is only used for domains.
205 typdefault is null if the type has no associated default value. If
206 typdefaultbin is not null, typdefault must contain a human-readable
207 version of the default expression represented by typdefaultbin. If
208 typdefaultbin is null and typdefault is not, then typdefault is the
209 external representation of the type's default value, which can be fed
210 to the type's input converter to produce a constant.
214 Access privileges; see Section 5.8 for details
218 For fixed-width types used in system tables, it is critical that the
219 size and alignment defined in pg_type agree with the way that the
220 compiler will lay out the column in a structure representing a table
223 Table 52.65 lists the system-defined values of typcategory. Any future
224 additions to this list will also be upper-case ASCII letters. All other
225 ASCII characters are reserved for user-defined categories.
227 Table 52.65. typcategory Codes
235 I Network address types