Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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...

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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];
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading