Converting an Integer to Enum in PostgreSQL
enums, integer, postgresql, sql, type-conversion
Solution
SELECT (ENUM_RANGE(NULL::bnfunctionstype))[s]
FROM generate_series(1, 5) s
Problem
I have created a custom data type enum like so: ``` create type "bnfunctionstype" as enum ( 'normal', 'library', 'import', 'thunk', 'adjustor_thunk' ); ``` 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. How can I do this? I'm using PostgreSQL 8.4.