Skip to content

Instantly share code, notes, and snippets.

@gjergjsheldija
Created December 3, 2012 12:51
Show Gist options
  • Save gjergjsheldija/4194848 to your computer and use it in GitHub Desktop.
Save gjergjsheldija/4194848 to your computer and use it in GitHub Desktop.
postgres change column from boolean to inetger
ALTER TABLE table_name ALTER column_name SET DEFAULT null;
ALTER TABLE table_name
ALTER column_name TYPE INTEGER
USING
CASE
WHEN false THEN 0
ELSE 1
END;
ALTER TABLE table_name ALTER column_name SET DEFAULT 0;
COMMIT;
@mattgibson
Copy link

Needs to be:

CASE column_name WHEN false THEN 0 ELSE 1 END;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment