Search code examples
postgresqlalembic

Use uppercase letters adding new enum value in postgresql


I have an enum datasetId, to which I'd like to add another value.

However, this doesn't work:

ALTER TYPE datasetId ADD VALUE 'SOME_VALUE'

and fails with

sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedObject) type "datasetid" does not exist

I believe this is because of the uppercase letter in the enum name. How to I get around that?


Solution

  • "I believe this is because of the uppercase letter in the enum name." -- Enclose identifiers with special characters or where casing matters in double quotes:

    ALTER TYPE "datasetId" ADD VALUE 'SOME_VALUE';
    

    Or, the recommended way, just don't use identifiers with special characters or meaningful casing at all. At the end of the day they're just annoying.