Switch to: V9V8V7V6V5

ALTER TYPE

Changes the definition of an existing type.

Syntax

alter_type_statement
    :    ALTER TYPE type_name alter_type_action
 
alter_type_action
    :    RENAME {TO | AS} type_name
 
    |    ADD VALUE  character_string_literal [, locale_name COLON character_string_literal ... ]
    |    ADD VALUES 
         { character_string_literal_list [, locale_character_string_literal_lists]
         | locale_character_string_literal_lists
         }
 
    |    CHANGE VALUE [locale_name COLON] character_string_literal TO character_string_literal
 
    |    DROP VALUES locale_name

There are several subforms.

  • RENAME - This form changes the name of the type or the name of an individual attribute of a composite type.
  • ADD VALUE - This form adds a new value to an enum type at the end of the list of values.
  • ADD VALUES - This form adds few new values to an enum type at the end of the list of values.
  • CHANGE VALUE - This form changes existed value of enum to new.
  • DROP VALUES - This form allows to drop set of value of some locale.

Examples

ALTER TYPE RENAME DaysOfWeek TO WeekDay;
CREATE TYPE DaysOfWeek AS ENUM();
 
ALTER TYPE DaysOfWeek ADD VALUE 'Sunday';
ALTER TYPE DaysOfWeek ADD VALUES ( 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' );
-- you can change one value if there was a typo or you want just modify it
--
ALTER TYPE DaysOfWeek CHANGE VALUE 'Tuesday' TO 'Tue';

Examples with Localization

-- ADD the whole set of values for locale 'ru'.
--
ALTER TYPE DaysOfWeek 
    ADD VALUES 'ru':( 'Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота' );
-- DROP the whole set of values for local 'ru'
--
ALTER TYPE DaysOfWeek 
    DROP VALUES 'ru';
-- CHANGE ONE VALUE in a specific locale:
--
ALTER TYPE DaysOfWeek 
    CAHNGE VALUE 'ru':'втАрник' TO 'вторник' ;