45.48. pg_type #
目录pg_type存储有关数据类型的信息。基础类型和枚举类型(标量类型)使用CREATE TYPE创建,而域使用CREATE DOMAIN创建。数据库中的每一个表都会有一个自动创建的复合类型,用于表示表的行结构。也可以使用CREATE TYPE AS创建复合类型。
表 45.48. pg_type 列
| Name | Type | References | Description |
|---|---|---|---|
typname | name | Data type name | |
typnamespace | oid | | The OID of the namespace that contains this type |
typowner | oid | | Owner of the type |
typlen | int2 | 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 | bool | 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 | char | typtype is
b for a base type,
c for a composite type (e.g., a table's row type),
d for a domain,
e for an enum type,
or p for a pseudo-type.
See also typrelid and
typbasetype.
| |
typcategory | char | typcategory is an arbitrary classification
of data types that is used by the parser to determine which implicit
casts should be “preferred”.
See 表 45.49.
| |
typispreferred | bool | True if the type is a preferred cast target within its
typcategory
| |
typisdefined | bool | 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 | char | 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 | 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 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.
|
typelem | 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 point.
If a fixed-length type has a typelem then
its internal representation must be some 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 typarray is not 0 then it
identifies another row in pg_type, which
is the “true” array type having this type as element
|
typinput | regproc | | Input conversion function (text format) |
typoutput | regproc | | Output conversion function (text format) |
typreceive | regproc | | Input conversion function (binary format), or 0 if none |
typsend | regproc | | Output conversion function (binary format), or 0 if none |
typmodin | regproc | | Type modifier input function, or 0 if type does not support modifiers |
typmodout | regproc | | Type modifier output function, or 0 to use the standard format |
typanalyze | regproc | | Custom ANALYZE function, or 0 to use the standard function |
typalign | char | 可能的值为:
注意 对于系统表中使用的类型,关键的是在 | |
typstorage | char |
注意, | |
typnotnull | bool | | |
typbasetype | oid | | 如果这是一个域(见 |
typtypmod | int4 | 域使用 | |
typndims | int4 | 对于基于数组的域, | |
typcollation | oid | | |
typdefaultbin | pg_node_tree | 如果 | |
typdefault | text | 如果某类型没有相关默认值,那么 |
表 45.49列出了typcategory的系统定义值。任何未来对此列表的增加都将是大写ASCII字母。所有其他ASCII字符都保留给用户定义的类别。
表 45.49. typcategory Codes
| Code | Category |
|---|---|
A | Array types |
B | Boolean types |
C | Composite types |
D | Date/time types |
E | Enum types |
G | Geometric types |
I | Network address types |
N | Numeric types |
P | Pseudo-types |
S | String types |
T | Timespan types |
U | User-defined types |
V | Bit-string types |
X | unknown type |