↑↓ 选择↵ 打开⌫ 切换范围完整搜索

PG.CENTER 连接 PostgreSQL 文档、百科与生态知识。由 Pigsty 维护。

支持中的版本: 当前版本 (18) / 17 / 16 / 15 / 14
开发中的版本: 19 / 20devel
已结束支持的版本: 13 / 12 / 11 / 10 / 9.6 / 9.5 / 9.4 / 9.3 / 9.2 / 9.1 / 9.0 / 8.4 / 8.3 / 8.2 / 8.1 / 8.0 / 7.4 / 7.3 / 7.2 / 7.1
历史版本。 PostgreSQL 9.1 已结束支持。 2016-10-27. 请参阅 当前版本手册.

45.48. pg_type #

目录pg_type存储有关数据类型的信息。基础类型和枚举类型(标量类型)使用CREATE TYPE创建,而域使用CREATE DOMAIN创建。数据库中的每一个表都会有一个自动创建的复合类型,用于表示表的行结构。也可以使用CREATE TYPE AS创建复合类型。

表 45.48. pg_type 列

NameTypeReferencesDescription
typnamename Data type name
typnamespaceoidpg_namespace.oid The OID of the namespace that contains this type
typowneroidpg_authid.oidOwner of the type
typlenint2  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.
typbyvalbool  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.
typtypechar  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.
typcategorychar  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.
typispreferredbool  True if the type is a preferred cast target within its typcategory
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, namespace, 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 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.
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 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.
typarrayoidpg_type.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
typinputregprocpg_proc.oidInput conversion function (text format)
typoutputregprocpg_proc.oidOutput conversion function (text format)
typreceiveregprocpg_proc.oidInput conversion function (binary format), or 0 if none
typsendregprocpg_proc.oidOutput conversion function (binary format), or 0 if none
typmodinregprocpg_proc.oidType modifier input function, or 0 if type does not support modifiers
typmodoutregprocpg_proc.oidType modifier output function, or 0 to use the standard format
typanalyzeregprocpg_proc.oidCustom ANALYZE function, or 0 to use the standard function
typalignchar 

typalign表示存储此类型值时所要求的对齐方式。它适用于磁盘存储,以及该值在 PostgreSQL 内部的大多数表示形式。当多个值连续存放时,例如在磁盘上完整行的表示中,这种类型的数据前会插入填充,使其从指定边界开始。对齐参考点是该序列中第一个数据的起始位置。

可能的值为:

  • c = char对齐,即不需要对齐。

  • s = short对齐(在大部分机器上为2字节)。

  • i = int对齐(在大部分机器上为4字节)。

  • d = double对齐(在很多机器上为8字节,但绝不是全部)。

注意

对于系统表中使用的类型,关键的是在pg_type定义的大小和对齐与编译器在表示表行的结构体中布局列的方式一致。

typstoragechar 

typstorage用于指示 varlena 类型(即typlen = -1)是否支持 TOAST,以及这种类型的属性应采用什么默认策略。可能的值为:

  • p:值必须始终以普通方式存储。

  • e:值可以存储在一个“二级”关系中(如果关系有这样的关系,参见pg_class.reltoastrelid)。

  • m:值可以被压缩并内联存储。

  • x:值可以被压缩并内联存储,或存储在“二级”存储中。

注意,m列也可以被移动到二级存储,但只能作为最后手段(e和x列会先被移动)。

typnotnullbool 

typnotnull表示类型上的一个非空约束。只用于域。

typbasetypeoidpg_type.oid

如果这是一个域(见typtype),则typbasetype标识该域所基于的类型。如果此类型不是域,则为 0。

typtypmodint4 

域使用typtypmod来记录被应用于它们基础类型的typmod(如果基础类型不使用typmod,则为-1)。如果此类型不是一个域则为-1。

typndimsint4 

对于基于数组的域,typndims是数组维度数(即,typbasetype是一个数组类型)。对于不是基于数组的域的类型,此列为零。

typcollationoidpg_collation.oid

typcollation指定此类型的排序规则。如果类型不支持排序规则,此列为零。支持排序规则的基础类型在这里会有DEFAULT_COLLATION_OID。基于支持排序规则的类型的域,如果为其指定了排序规则 OID,则它的排序规则 OID 可以不同于其基础类型的排序规则 OID。

typdefaultbinpg_node_tree 

如果typdefaultbin非空,那么它就是该类型默认表达式的nodeToString()表示形式。此列只用于域。

typdefaulttext 

如果某类型没有相关默认值,那么typdefault为空。如果typdefaultbin不为空,那么typdefault必须包含由typdefaultbin表示的默认表达式的人类可读版本。如果typdefaultbin为空而typdefault不为空,则typdefault是该类型默认值的外部表示形式,它可以被交给该类型的输入转换器来产生一个常量。


表 45.49列出了typcategory的系统定义值。任何未来对此列表的增加都将是大写ASCII字母。所有其他ASCII字符都保留给用户定义的类别。

表 45.49. typcategory Codes

CodeCategory
AArray types
BBoolean types
CComposite types
DDate/time types
EEnum types
GGeometric types
INetwork address types
NNumeric types
PPseudo-types
SString types
TTimespan types
UUser-defined types
VBit-string types
Xunknown type

报告文档问题

阅读 上游文档. 反馈更正前请先核对 当前版本手册.