gpt4 book ai didi

sql - 在 PostgreSQL 中将整数转换为枚举

转载 作者:行者123 更新时间:2023-11-29 11:18:48 30 4
gpt4 key购买 nike

我创建了一个自定义数据类型枚举,如下所示:

create type "bnfunctionstype" as enum ( 
'normal',
'library',
'import',
'thunk',
'adjustor_thunk'
);

我从外部数据源获得 [0,4] 范围内的整数。我想将这些整数转换为它们相应的枚举值。

我该怎么做?

我正在使用 PostgreSQL 8.4。

最佳答案

SELECT (ENUM_RANGE(NULL::bnfunctionstype))[s]
FROM generate_series(1, 5) s

关于sql - 在 PostgreSQL 中将整数转换为枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1827122/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com