Postgresql 中文操作指南

53.20. pg_enum #

pg_enum 目录包含显示每个枚举类型的值和标签的条目。给定枚举值的内部表示实际上是其在 pg_enum 中关联行的 OID。

The pg_enum catalog contains entries showing the values and labels for each enum type. The internal representation of a given enum value is actually the OID of its associated row in pg_enum.

Table 53.20. pg_enum Columns

Table 53.20. pg_enum Columns

Column Type

Description

oid oid

Row identifier

enumtypid oid (references pg_type.oid)

The OID of the pg_type entry owning this enum value

enumsortorder float4

The sort position of this enum value within its enum type

enumlabel name

The textual label for this enum value

pg_enum 行的 OID 遵循特殊规则:保证偶数编号的 OID 按其枚举类型的排序顺序排序。即,如果两个偶数 OID 属于同一个枚举类型,则较小的 OID 必须具有较小的 enumsortorder 值。奇数编号的 OID 值无需与排序顺序有任何关系。此规则允许枚举比较例程在许多常见情况下避免目录查找。尽可能创建和更改枚举类型的例程会尝试为枚举值分配偶数 OID。

The OIDs for pg_enum rows follow a special rule: even-numbered OIDs are guaranteed to be ordered in the same way as the sort ordering of their enum type. That is, if two even OIDs belong to the same enum type, the smaller OID must have the smaller enumsortorder value. Odd-numbered OID values need bear no relationship to the sort order. This rule allows the enum comparison routines to avoid catalog lookups in many common cases. The routines that create and alter enum types attempt to assign even OIDs to enum values whenever possible.

创建枚举类型时,其成员被分配排序顺序位置 1..n。但稍后添加的成员可能获得 enumsortorder 的负或分数值。这些值唯一的要求是其必须在每个枚举类型中正确排序且唯一。

When an enum type is created, its members are assigned sort-order positions 1..n. But members added later might be given negative or fractional values of enumsortorder. The only requirement on these values is that they be correctly ordered and unique within each enum type.