public inbox for [email protected]
help / color / mirror / Atom feeddoc: Clarify ALTER CONSTRAINT enforceability wording
2+ messages / 1 participants
[nested] [flat]
* doc: Clarify ALTER CONSTRAINT enforceability wording
@ 2026-05-25 09:31 Chao Li <[email protected]>
2026-05-26 05:42 ` Re: doc: Clarify ALTER CONSTRAINT enforceability wording Chao Li <[email protected]>
0 siblings, 1 reply; 2+ messages in thread
From: Chao Li @ 2026-05-25 09:31 UTC (permalink / raw)
To: PostgreSQL Hackers <[email protected]>; +Cc: Andrew Dunstan <[email protected]>; jian he <[email protected]>
Hi,
I just started to test “Add support for altering CHECK constraint enforceability”. I read the related ALTER TABLE doc first, and found it a bit confusing:
```
ALTER CONSTRAINT
This form alters the attributes of a constraint that was previously created. Currently FOREIGN KEY and CHECK constraints may be altered in this fashion, but see below.
```
In the feature commit 342051d73, only “CHECK" was added:
```
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -578,8 +578,8 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
<listitem>
<para>
This form alters the attributes of a constraint that was previously
- created. Currently only foreign key constraints may be altered in
- this fashion, but see below.
+ created. Currently <literal>FOREIGN KEY</literal> and <literal>CHECK</literal>
+ constraints may be altered in this fashion, but see below.
</para>
```
However, the last phrase “but see below” is quite confusing. I read the doc several times up and down, and finally my best guess is that “see below” refers to the immediately following paragraph’s sentence “Only not-null constraints may be altered in this fashion at present”, but the sentence does not say anything about enforceability.
```
ALTER CONSTRAINT ... INHERIT
ALTER CONSTRAINT ... NO INHERIT
These forms modify an inheritable constraint so that it becomes not inheritable, or vice-versa. **Only not-null constraints may be altered in this fashion at present.** In addition to changing the inheritability status of the constraint, in the case where a non-inheritable constraint is being marked inheritable, if the table has children, an equivalent constraint will be added to them. If marking an inheritable constraint as non-inheritable on a table with children, then the corresponding constraint on children will be marked as no longer inherited, but not removed.
```
As I understand it, the current behavior is:
* Deferrability attributes can only be altered for FOREIGN KEY constraints
* Enforceability attributes can be altered for both FOREIGN KEY and CHECK constraints, and CHECK support was newly added by 342051d73 for v19
To remove the confusion, I updated the documentation. See the attached patch for details.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
Attachments:
[application/octet-stream] v1-0001-doc-Clarify-ALTER-CONSTRAINT-enforceability-behav.patch (2.1K, 2-v1-0001-doc-Clarify-ALTER-CONSTRAINT-enforceability-behav.patch)
download | inline diff:
From 321421de15be0a09ae5cd71317d0deeb50173c9b Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <[email protected]>
Date: Mon, 25 May 2026 16:59:21 +0800
Subject: [PATCH v1] doc: Clarify ALTER CONSTRAINT enforceability behavior
The ALTER TABLE documentation said that FOREIGN KEY and CHECK
constraints may be altered, but did not distinguish between
deferrability and enforceability attributes.
Clarify that deferrability attributes can currently be altered only for
FOREIGN KEY constraints, while enforceability can be altered for both
FOREIGN KEY and CHECK constraints. Also document that setting a
constraint to ENFORCED verifies existing rows and resumes checking new
or updated rows.
Author: Chao Li <[email protected]>
---
doc/src/sgml/ref/alter_table.sgml | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index dec34337d1a..af247d82902 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -586,8 +586,18 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
<listitem>
<para>
This form alters the attributes of a constraint that was previously
- created. Currently <literal>FOREIGN KEY</literal> and <literal>CHECK</literal>
- constraints may be altered in this fashion, but see below.
+ created. Currently, the deferrability attributes can be altered only
+ for <literal>FOREIGN KEY</literal> constraints. The enforceability
+ attribute can be altered for <literal>FOREIGN KEY</literal> and
+ <literal>CHECK</literal> constraints.
+ </para>
+
+ <para>
+ Setting a constraint to <literal>NOT ENFORCED</literal> causes the
+ database system to stop checking it for new or updated rows. Setting
+ a constraint to <literal>ENFORCED</literal> causes the database system
+ to verify that existing rows satisfy the constraint and to check it
+ for new or updated rows.
</para>
</listitem>
</varlistentry>
--
2.50.1 (Apple Git-155)
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: doc: Clarify ALTER CONSTRAINT enforceability wording
2026-05-25 09:31 doc: Clarify ALTER CONSTRAINT enforceability wording Chao Li <[email protected]>
@ 2026-05-26 05:42 ` Chao Li <[email protected]>
0 siblings, 0 replies; 2+ messages in thread
From: Chao Li @ 2026-05-26 05:42 UTC (permalink / raw)
To: PostgreSQL Hackers <[email protected]>; +Cc: Andrew Dunstan <[email protected]>; jian he <[email protected]>
> On May 25, 2026, at 17:31, Chao Li <[email protected]> wrote:
>
> Hi,
>
> I just started to test “Add support for altering CHECK constraint enforceability”. I read the related ALTER TABLE doc first, and found it a bit confusing:
> ```
> ALTER CONSTRAINT
> This form alters the attributes of a constraint that was previously created. Currently FOREIGN KEY and CHECK constraints may be altered in this fashion, but see below.
> ```
>
> In the feature commit 342051d73, only “CHECK" was added:
> ```
> --- a/doc/src/sgml/ref/alter_table.sgml
> +++ b/doc/src/sgml/ref/alter_table.sgml
> @@ -578,8 +578,8 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
> <listitem>
> <para>
> This form alters the attributes of a constraint that was previously
> - created. Currently only foreign key constraints may be altered in
> - this fashion, but see below.
> + created. Currently <literal>FOREIGN KEY</literal> and <literal>CHECK</literal>
> + constraints may be altered in this fashion, but see below.
> </para>
> ```
>
> However, the last phrase “but see below” is quite confusing. I read the doc several times up and down, and finally my best guess is that “see below” refers to the immediately following paragraph’s sentence “Only not-null constraints may be altered in this fashion at present”, but the sentence does not say anything about enforceability.
> ```
> ALTER CONSTRAINT ... INHERIT
> ALTER CONSTRAINT ... NO INHERIT
> These forms modify an inheritable constraint so that it becomes not inheritable, or vice-versa. **Only not-null constraints may be altered in this fashion at present.** In addition to changing the inheritability status of the constraint, in the case where a non-inheritable constraint is being marked inheritable, if the table has children, an equivalent constraint will be added to them. If marking an inheritable constraint as non-inheritable on a table with children, then the corresponding constraint on children will be marked as no longer inherited, but not removed.
> ```
>
> As I understand it, the current behavior is:
> * Deferrability attributes can only be altered for FOREIGN KEY constraints
> * Enforceability attributes can be altered for both FOREIGN KEY and CHECK constraints, and CHECK support was newly added by 342051d73 for v19
>
> To remove the confusion, I updated the documentation. See the attached patch for details.
>
> Best regards,
> --
> Chao Li (Evan)
> HighGo Software Co., Ltd.
> https://www.highgo.com/
>
>
>
>
> <v1-0001-doc-Clarify-ALTER-CONSTRAINT-enforceability-behav.patch>
As I found a bug of the feature and proposed a fix in [1], let's merge this thread into that one, as they are for the same feature.
[1] https://postgr.es/m/[email protected]
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2026-05-26 05:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-05-25 09:31 doc: Clarify ALTER CONSTRAINT enforceability wording Chao Li <[email protected]>
2026-05-26 05:42 ` Chao Li <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox