简体   繁体   中英

Convert postgres column type from enum to array of enums

I currently have a table called employees having column access_level of type enum (accessLevel). But now I want to provide the employee multiple access_levels so now I need to convert the datatype from enum to array of enum.

I ran the following query

ALTER TABLE employees ALTER COLUMN access_level TYPE accessLevel[] USING access_level::accessLevel[]

But in response getting the following error
ERROR: cannot cast type accessLevel to accessLevel[] LINE 1: ... access_level TYPE accessLevel[] USING access_level::accessLev...

You can't cast a single value to an array, you need to build a new array:

ALTER TABLE employees 
    ALTER COLUMN access_level TYPE accessLevel[] 
    USING array[access_level];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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