Sample Header Ad - 728x90

Is it safe to use default value with not null when adding a new column?

7 votes
1 answer
19729 views
We have a Rails app powered by Postgresql *v11.4* where I want to add a new column with a default value and a not null constraint like below: ALTER TABLE "blogs" ADD "published" boolean DEFAULT FALSE NOT NULL I know adding a new column with a default value is safe. However, is it still safe when combined with NOT NULL? Or will it lock the database? Thanks!
Asked by ogirginc (275 rep)
May 12, 2022, 11:14 AM
Last activity: May 12, 2022, 01:35 PM