简体   繁体   English

如何创建包含一组枚举值的PostgreSQL列?

[英]How to create a PostgreSQL column that is a set of enum values?

I like that I can create new enum types in PostgreSQL . 我喜欢我可以在PostgreSQL中创建新的枚举类型 But what if I want a column value that is a set of enum values. 但是,如果我想要一枚举值的列值怎么办。 Do I need to implement that manually with an integer column type and bitwise operators, or is there a way to keep using the enums by name? 我是否需要使用整数列类型和按位运算符手动实现该功能,还是有办法按名称继续使用枚举?

CREATE TYPE foo AS ENUM ('none', 'loud', 'bright', 'cheap')
CREATE TABLE t (
    id serial,
    properties [set of foo?]
)
...
SELECT * FROM t;
1      loud
2      loud, cheap
3      bright
4      none
...

You can use an array: 您可以使用数组:

CREATE TYPE foo AS ENUM ('none', 'loud', 'bright', 'cheap');
CREATE TABLE t (
    id serial,
    properties foo[]
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM