Skip to content

Instantly share code, notes, and snippets.

@siteshen
Created January 23, 2015 06:07
Show Gist options
  • Select an option

  • Save siteshen/db2098787a918de60f7c to your computer and use it in GitHub Desktop.

Select an option

Save siteshen/db2098787a918de60f7c to your computer and use it in GitHub Desktop.
Example of adding default value to column having millions of rows.
-- ALTER TABLE users ADD COLUMN deleted boolean NOT NULL DEFAULT false;
ALTER TABLE users ADD COLUMN deleted boolean;
ALTER TABLE users ALTER COLUMN deleted SET DEFAULT false;
UPDATE users SET deleted = false WHERE deleted IS NULL;
ALTER TABLE users ALTER COLUMN deleted SET NOT NULL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment