数据仓库服务 GAUSSDB(DWS)-枚举类型:枚举类型的声明

时间:2024-12-06 15:12:47

枚举类型的声明

枚举类型可以使用CREATE TYPE命令创建,例如:

1
CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');

枚举类型被创建后,可以在表和函数定义中使用:

1
2
3
4
5
6
7
8
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)
support.huaweicloud.com/sqlreference-910-dws/dws_06_0369.html