Skip to content

Commit d0654e5

Browse files
author
Álvaro Herrera
committed
doc: mention unusability of dropped CHECK to verify NOT NULL
It's possible to use a CHECK (col IS NOT NULL) constraint to skip scanning a table for nulls when adding a NOT NULL constraint on the same column. However, if the CHECK constraint is dropped on the same command that the NOT NULL is added, this fails, i.e., makes the NOT NULL addition slow. The best we can do about it at this stage is to document this so that users aren't taken by surprise. (In Postgres 18 you can directly add the NOT NULL constraint as NOT VALID instead, so there's no longer much use for the CHECK constraint, therefore no point in building mechanism to support the case better.) Reported-by: Andrew <psy2000usa@yahoo.com> Reviewed-by: David G. Johnston <david.g.johnston@gmail.com> Discussion: https://postgr.es/m/175385113607.786.16774570234342968908@wrigleys.postgresql.org
1 parent f5a4932 commit d0654e5

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

doc/src/sgml/ref/alter_table.sgml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
225225
provided none of the records in the table contain a
226226
<literal>NULL</literal> value for the column. Ordinarily this is
227227
checked during the <literal>ALTER TABLE</literal> by scanning the
228-
entire table; however, if a valid <literal>CHECK</literal> constraint is
229-
found which proves no <literal>NULL</literal> can exist, then the
230-
table scan is skipped.
228+
entire table;
229+
however, if a valid <literal>CHECK</literal> constraint exists
230+
(and is not dropped in the same command) which proves no
231+
<literal>NULL</literal> can exist, then the table scan is skipped.
231232
</para>
232233

233234
<para>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy