Converting an Integer to Enum in PostgreSQL

前端 未结 3 1036
终归单人心
终归单人心 2021-02-20 15:09

I have created a custom data type enum like so:

create type \"bnfunctionstype\" as enum ( 
    \'normal\', 
    \'library\', 
    \'import\', 
    \'thunk\', 
           


        
3条回答
  •  遇见更好的自我
    2021-02-20 15:47

    create function bnfunctionstype_from_number(int)
        returns bnfunctionstype
        immutable strict language sql as
    $$
        select case ?
            when 0 then 'normal'
            when 1 then 'library'
            when 2 then 'import'
            when 3 then 'thunk'
            when 4 then 'adjustor_thunk'
            else null
        end
    $$;
    

提交回复
热议问题