PostgreSQL 系统表pg_enum

来源:互联网 发布:2018年淘宝卖什么好 编辑:程序博客网 时间:2024/05/21 11:08

pg_enum表包含显示每个枚举类型值和标签的记录。

名字类型引用描述oidoid 行标识符(隐藏属性; 必须明确选择)enumtypidoidpg_type.oid拥有这个枚举值的pg_type记录的OIDenumsortorderfloat4 这个枚举值在它的枚举类型中的排序位置enumlabelname 这个枚举值的文本标签



实例

postgres=# select * from pg_enum ;(No rows)
  • 1
  • 2
  • 1
  • 2

可以看到系统表此时还没有枚举类型,我们可以自己定义一个枚举类型。

postgres=# create type mood as enum('sad','ok','happy');CREATE TYPEpostgres=postgres=# select * from pg_enum ; enumtypid | enumsortorder | enumlabel -----------+---------------+-----------     65750 |             1 | sad     65750 |             2 | ok     65750 |             3 | happy(3 rows)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

enumtypid是对应表pg_type的oid,因为它也是一中可以使用的数据类型。

postgres=# select * from pg_type where oid=65750 ;-[ RECORD 1 ]--+----------typname        | moodtypnamespace   | 2200typowner       | 10typlen         | 4typbyval       | ttyptype        | etypcategory    | Etypispreferred | ftypisdefined   | ttypdelim       | ,typrelid       | 0typelem        | 0typarray       | 65749typinput       | enum_intypoutput      | enum_outtypreceive     | enum_recvtypsend        | enum_sendtypmodin       | -typmodout      | -typanalyze     | -typalign       | itypstorage     | ptypnotnull     | ftypbasetype    | 0typtypmod      | -1typndims       | 0typcollation   | 0typdefaultbin  | typdefault     | typacl         |
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

typname是我们定义的mood。



枚举类型的使用参考: PostgreSQL enum的使用

原创粉丝点击