You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/adding-field-with-default.md
+34Lines changed: 34 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,6 +45,40 @@ We add our column as nullable, set a default for new rows, backfill our column (
45
45
See ["How not valid constraints work"](constraint-missing-not-valid.md#how-not-valid-validate-works) for more information on adding constraints as `NOT VALID`.
46
46
47
47
48
+
### Adding a generated column
49
+
50
+
Adding a generated column in Postgres will cause a table rewrite, locking the table while the update completes.
51
+
52
+
Instead of using a generated column, use a trigger.
53
+
54
+
55
+
Instead of:
56
+
57
+
```sql
58
+
ALTERTABLE"core_recipe" ADD COLUMN "foo"integer GENERATED ALWAAYS as ("bar"+"baz") STORED;
59
+
```
60
+
61
+
Use:
62
+
63
+
```sql
64
+
ALTERTABLE"core_recipe" ADD COLUMN "foo"integer;
65
+
66
+
-- backfill column in batches
67
+
68
+
-- add a trigger to match the generated column behavior
0 commit comments