Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to alter type and remove value in postgresql [duplicate]

I found how to add value to the TYPE. But how can I remove value from it?
For example I have TYPE with enum values ('A','B','C'). How to remove 'C'?

like image 588
Alex Avatar asked Sep 17 '14 11:09

Alex


People also ask

How can I change PostgreSQL type?

You must own the type to use ALTER TYPE . To change the schema of a type, you must also have CREATE privilege on the new schema. To alter the owner, you must also be a direct or indirect member of the new owning role, and that role must have CREATE privilege on the type's schema.

How do I change the datatype of a column in PostgreSQL?

First, specify the name of the table to which the column you want to change belongs in the ALTER TABLE clause. Second, give the name of column whose data type will be changed in the ALTER COLUMN clause. Third, provide the new data type for the column after the TYPE keyword.

How do you change values in PostgreSQL?

First, specify the name of the table that you want to update data after the UPDATE keyword. Second, specify columns and their new values after SET keyword. The columns that do not appear in the SET clause retain their original values. Third, determine which rows to update in the condition of the WHERE clause.


1 Answers

To remove value ('val1') from enum ('enum_test') you can use:

DELETE FROM pg_enum WHERE enumlabel = 'val1' AND enumtypid = (   SELECT oid FROM pg_type WHERE typname = 'enum_test' ) 
like image 69
snaiffer Avatar answered Sep 22 '22 08:09

snaiffer