在PostgreSQL中将整数转换为枚举 [英] Converting an Integer to Enum in PostgreSQL

查看:156
本文介绍了在PostgreSQL中将整数转换为枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have created a custom data type enum like so:

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

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

From an external data source I get integers in the range [0,4]. I'd like to convert these integers to their corresponding enum values.

我该怎么做?

我使用PostgreSQL 8.4。

I'm using PostgreSQL 8.4.

推荐答案

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

这篇关于在PostgreSQL中将整数转换为枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆