From: | PG Doc comments form <noreply(at)postgresql(dot)org> |
---|---|
To: | pgsql-docs(at)lists(dot)postgresql(dot)org |
Cc: | him(at)nathanmlong(dot)com |
Subject: | Show how to incrementally make a column NOT NULL |
Date: | 2023-10-09 18:34:38 |
Message-ID: | 169687647875.650.18286290464025494214@wrigleys.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-docs |
The following documentation comment has been logged on the website:
Page: https://www.postgresql.org/docs/16/sql-altertable.html
Description:
In the examples on
https://www.postgresql.org/docs/current/sql-altertable.html#SQL-ALTERTABLE-NOTES,
I suggest adding the following.
To make an existing column `NOT NULL` with the least impact on other work:
```
-- prevent new NULL values
ALTER TABLE distributors ADD CONSTRAINT street_not_null CHECK (street IS NOT
NULL) NOT VALID;
-- optionally, pause here to fix existing NULL values
ALTER TABLE distributors VALIDATE CONSTRAINT street_not_null;
ALTER TABLE distributors ALTER COLUMN street SET NOT NULL;
-- check constraint no longer needed
ALTER TABLE distributors DROP CONSTRAINT street_not_null;
```
From | Date | Subject | |
---|---|---|---|
Next Message | PG Doc comments form | 2023-10-10 05:32:12 | Setting up WAL archiving |
Previous Message | Brad White | 2023-10-09 17:34:26 | Re: ODBC options |