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)