问题
Using the following:
CREATE TYPE user_types AS ENUM ('it', 'accounting', 'processes');
CREATE TABLE my_users
(
my_user_id integer NOT NULL,
my_user_name text NOT NULL,
my_user_type user_types
)
I want to change one of the user types:
ALTER TYPE user_types RENAME ATTRIBUTE it TO softwaredev CASCADE;
I get a error:
ERROR: relation "user_types" does not exist
SQL state: 42P01
I tried adding quotes and backticks but that didn't help. The example I wrote down here is not the exact code, my type has 31 characters, but I don't think the length of my type is the issue.
I'm using postgres version 9.6.2
回答1:
ALTER TYPE ... RENAME ATTRIBUTE
only works for composite types, not for ENUM
types.
While there is a way to add new entries to such a type (ALTER TYPE ... ADD VALUE 'new_value'
), there is no supported way to remove or rename an enumeration entry.
If you are not afraid to mess with the catalogs, you can try as superuser:
UPDATE pg_enum
SET enumlabel = 'softwaredev'
WHERE enumtypid = 'user_types'::regtype
AND enumlabel = 'it';
From PostgreSQL v10 on, you can use
ALTER TYPE ... RENAME VALUE ... TO ...
来源:https://stackoverflow.com/questions/44243336/error-on-alter-type-in-postgres-relation-does-not-exist