error: ALTER TYPE … ADD cannot run inside a transaction block

后端 未结 4 1381
温柔的废话
温柔的废话 2021-02-12 11:22

I am trying to add new type value to my existing types in PostgreSQL. But I get the following error

error: ALTER TYPE ... ADD cannot run inside a transact

4条回答
  •  梦谈多话
    2021-02-12 12:08

    Workaround for earlier versions of PostgreSQL shown here:

    Note this will require special permissions because it changes a system table.

    • Replace 'NEW_ENUM_VALUE' with the value you want.
    • Replace'type_egais_units' with the oid of the enum you want to change. (Use SELECT * FROM pg_enum to find the enum you want to update, in my case it was a 5-digit number like '19969')

    The statement:

    INSERT INTO pg_enum (
        enumtypid, 
        enumlabel, 
        enumsortorder
    )
    SELECT 
        'type_egais_units'::regtype::oid, 
        'NEW_ENUM_VALUE', 
        (SELECT MAX(enumsortorder) + 1 FROM pg_enum WHERE enumtypid = 'type_egais_units'::regtype)
    

    Of course , upgrading PostgreSQL as suggested in the accepted answer, is probably the best.

    Does anyone know how to avoid using transactions when running queries from pgAdmin Version 3.5? (i.e. when executing with F5?)

提交回复
热议问题