跳转到主要内容
← 目录图谱 / pg_type

SYSTEM CATALOG · 系统目录

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.

首次收录 PG 9.0最近收录 PG 19当前字段 32

已与 PostgreSQL 18.6 实例逐字段核对 · 原始实测记录 ↗

字段结构 PostgreSQL 18

pg_type
字段 / COLUMN类型 / TYPE说明 / DESCRIPTION
oid oidNOT NULL Row identifier
typname nameNOT NULL Data type name
typnamespace oidNOT NULL The OID of the namespace that contains this type引用:pg_namespace.oid
typowner oidNOT NULL Owner of the type引用:pg_authid.oid
typlen smallintNOT NULL文档原写法: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 booleanNOT NULL文档原写法: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"NOT NULL文档原写法: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, p for a pseudo-type, r for a range type, or m for a multirange type. See also typrelid and typbasetype.
typcategory "char"NOT NULL文档原写法:char typcategory is an arbitrary classification of data types that is used by the parser to determine which implicit casts should be “preferred”. See Table 52.65.
typispreferred booleanNOT NULL文档原写法:bool True if the type is a preferred cast target within its typcategory
typisdefined booleanNOT NULL文档原写法: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"NOT NULL文档原写法: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 oidNOT NULL 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.引用:pg_class.oid
typsubscript regprocNOT NULL Subscripting handler function's OID, or zero if this type doesn't support subscripting. Types that are “true” array types have typsubscript = array_subscript_handler, but other types may have other handler functions to implement specialized subscripting behavior.引用:pg_proc.oid
typelem oidNOT NULL 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.引用:pg_type.oid
typarray oidNOT NULL If typarray is not zero then it identifies another row in pg_type, which is the “true” array type having this type as element引用:pg_type.oid
typinput regprocNOT NULL Input conversion function (text format)引用:pg_proc.oid
typoutput regprocNOT NULL Output conversion function (text format)引用:pg_proc.oid
typreceive regprocNOT NULL Input conversion function (binary format), or zero if none引用:pg_proc.oid
typsend regprocNOT NULL Output conversion function (binary format), or zero if none引用:pg_proc.oid
typmodin regprocNOT NULL Type modifier input function, or zero if type does not support modifiers引用:pg_proc.oid
typmodout regprocNOT NULL Type modifier output function, or zero to use the standard format引用:pg_proc.oid
typanalyze regprocNOT NULL Custom ANALYZE function, or zero to use the standard function引用:pg_proc.oid
typalign "char"NOT NULL文档原写法:char 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 "char"NOT NULL文档原写法:char 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: x is the usual choice for toast-able types. Note that m values can also be moved out to secondary storage, but only as a last resort (e and x values are moved first).
typnotnull booleanNOT NULL文档原写法:bool typnotnull represents a not-null constraint on a type. Used for domains only.
typbasetype oidNOT NULL 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.引用:pg_type.oid
typtypmod integerNOT NULL文档原写法:int4 Domains use typtypmod to record the typmod to be applied to their base type (-1 if base type does not use a typmod). -1 if this type is not a domain.
typndims integerNOT NULL文档原写法:int4 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 oidNOT NULL 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 DEFAULT_COLLATION_OID. A domain over a collatable type can have a collation OID different from its base type's, if one was specified for the domain.引用:pg_collation.oid
typdefaultbin pg_node_tree If typdefaultbin is not null, it is the nodeToString() representation of a default expression for the type. This is only used for domains.
typdefault text 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 aclitem[] Access privileges; see Section 5.8 for details

标记“隐式列”的字段不包含在 SELECT * 中;部分早期统计视图由同版本源码补全,额外来源会显示在字段说明中。

通用系统列 6

PostgreSQL 提供的系统属性,通常不在 SELECT * 中展开。单独保留,不与普通字段混算。

字段类型attnum
tableoidoid-6
cmaxcid-5
xmaxxid-4
cmincid-3
xminxid-2
ctidtid-1

字段演化矩阵

悬停查看字段类型
存在新增 / 类型或属性变化移除
字段 / COLUMN9.09.19.29.39.49.59.610111213141516171819
oid
typname
typnamespace
typowner
typlen
typbyval
typtype
typcategory
typispreferred
typisdefined
typdelim
typrelid
typelem
typarray
typinput
typoutput
typreceive
typsend
typmodin
typmodout
typanalyze
typalign
typstorage
typnotnull
typbasetype
typtypmod
typndims
typdefaultbin
typdefault
typcollation
typacl
typsubscript

9.0 是收录基线;基线中已存在的字段不标记为新增。矩阵按字段名称对齐,重命名显示为旧字段移除与新字段新增。

演化时间线

相邻大版本的变化

PostgreSQL 19 ← 18

2 处字段说明更新

PostgreSQL 18 ← 17

1 处字段说明更新

PostgreSQL 17 ← 16

2 处字段说明更新

PostgreSQL 15 ← 14

1 处字段说明更新

PostgreSQL 14 ← 13

+ typsubscript9 处字段说明更新

PostgreSQL 13 ← 12

3 处字段说明更新

PostgreSQL 12 ← 11

~ oid: 隐式列 → 常规列4 处字段说明更新

PostgreSQL 11 ← 10

1 处字段说明更新

PostgreSQL 10 ← 9.6

6 处字段说明更新

PostgreSQL 9.6 ← 9.5

1 处字段说明更新

PostgreSQL 9.5 ← 9.4

1 处字段说明更新

PostgreSQL 9.4 ← 9.3

1 处字段说明更新

PostgreSQL 9.3 ← 9.2

2 处字段说明更新

PostgreSQL 9.2 ← 9.1

+ typacl2 处字段说明更新

PostgreSQL 9.1 ← 9.0

+ typcollation~ typdefaultbin: text → pg_node_tree3 处字段说明更新

比较任意两个版本

选择两个版本,查看字段的新增、移除与类型变化。交互比较需要 JavaScript;演化时间线可直接阅读。