Skip to content

Instantly share code, notes, and snippets.

@mykhailokrainik
Created October 23, 2018 13:42
Show Gist options
  • Save mykhailokrainik/a7e90d55a43fe0dbcff7be8c0d890757 to your computer and use it in GitHub Desktop.
Save mykhailokrainik/a7e90d55a43fe0dbcff7be8c0d890757 to your computer and use it in GitHub Desktop.
PG add not null values column with array type
ALTER TABLE users
ADD COLUMN positions INTEGER[] NULL;
UPDATE users SET positions = '{}';
ALTER TABLE users
ALTER COLUMN positions SET NOT NULL;
-- +-----------------+--------------------------+----------------------------------------------------------+
-- | Column | Type | Modifiers |
-- |-----------------+--------------------------+----------------------------------------------------------|
-- | ... | ... | ... |
-- | positions | integer[] | not null |
-- +-----------------+--------------------------+----------------------------------------------------------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment