8.7.1. Declaration of Enumerated Types

8.7.1. Declaration of Enumerated Types
8.7.1.声明枚举类型
Enum types are created using the CREATE TYPE command, for example: 
使用 CREATE TYPE命令创建枚举类型,例如:
 
CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
 
Once created, the enum type can be used in table and function definitions much like any other type:
创建之后,枚举类型即可像其他数据类型一样用在表和函数定义中:
 
CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
CREATE TABLE person (
name text,
current_mood mood
);
INSERT INTO person VALUES ('Moe', 'happy');
SELECT * FROM person WHERE current_mood = 'happy';
name | current_mood
------+--------------
Moe | happy
(1 row)
 
发布了341 篇原创文章 · 获赞 54 · 访问量 88万+

猜你喜欢

转载自blog.csdn.net/ghostliming/article/details/104662947
今日推荐