Skip to main content
added 87 characters in body
Source Link
Vao Tsun
  • 52.6k
  • 13
  • 115
  • 150

You can "compress" it by one step with USING, like:

alter table abc alter COLUMN abc_integer set data type abc_enum_type using case when abc_integer == 1 THEN 'hi'::abc_enum_type ELSE 'hello'::abc_enum_type END; 

and then renaming the column abc_integer to abc_enum.

If that what you want it works on 9.3

Btw! Mind default values.

Edit The way you do it does not lock the table. While altering column type will!

You can "compress" it by one step with USING, like:

alter table abc alter COLUMN abc_integer set data type abc_enum_type using case when abc_integer == 1 THEN 'hi'::abc_enum_type ELSE 'hello'::abc_enum_type END; 

and then renaming the column abc_integer to abc_enum.

If that what you want it works on 9.3

Btw! Mind default values.

You can "compress" it by one step with USING, like:

alter table abc alter COLUMN abc_integer set data type abc_enum_type using case when abc_integer == 1 THEN 'hi'::abc_enum_type ELSE 'hello'::abc_enum_type END; 

and then renaming the column abc_integer to abc_enum.

If that what you want it works on 9.3

Btw! Mind default values.

Edit The way you do it does not lock the table. While altering column type will!

Source Link
Vao Tsun
  • 52.6k
  • 13
  • 115
  • 150

You can "compress" it by one step with USING, like:

alter table abc alter COLUMN abc_integer set data type abc_enum_type using case when abc_integer == 1 THEN 'hi'::abc_enum_type ELSE 'hello'::abc_enum_type END; 

and then renaming the column abc_integer to abc_enum.

If that what you want it works on 9.3

Btw! Mind default values.