Skip to content

Instantly share code, notes, and snippets.

@fredj
Created July 5, 2012 15:01
Show Gist options
  • Save fredj/3054199 to your computer and use it in GitHub Desktop.
Save fredj/3054199 to your computer and use it in GitHub Desktop.
postgresql update enum (< 9.1)
BEGIN;
ALTER TABLE missionevents ADD COLUMN type_text text;
UPDATE missionevents SET type_text = type::text;
DROP TYPE missionevent_type CASCADE;
CREATE TYPE missionevent_type AS ENUM ('location', 'battery_level', 'start', 'end', 'cancel', 'light', 'expire', 'battery_low', 'comment', 'warning', 'error', 'temperature_list', 'temperature_low', 'temperature_high');
ALTER TABLE missionevents ADD COLUMN type missionevent_type;
UPDATE missionevents SET type = type_text::missionevent_type;
ALTER TABLE missionevents DROP COLUMN type_text;
ROLLBACK;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment