1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Allow CHECK constraints to be declared ONLY

This makes them enforceable only on the parent table, not on children
tables.  This is useful in various situations, per discussion involving
people bitten by the restrictive behavior introduced in 8.4.

Message-Id:
8762mp93iw.fsf@comcast.net
CAFaPBrSMMpubkGf4zcRL_YL-AERUbYF_-ZNNYfb3CVwwEqc9TQ@mail.gmail.com

Authors: Nikhil Sontakke, Alex Hunsaker
Reviewed by Robert Haas and myself
This commit is contained in:
Alvaro Herrera
2011-12-05 15:10:18 -03:00
parent 9220362493
commit 61d81bd28d
19 changed files with 212 additions and 79 deletions

View File

@ -2036,6 +2036,16 @@
</entry>
</row>
<row>
<entry><structfield>conisonly</structfield></entry>
<entry><type>bool</type></entry>
<entry></entry>
<entry>
This constraint is defined locally for the relation. It is a
non-inheritable constraint.
</entry>
</row>
<row>
<entry><structfield>conkey</structfield></entry>
<entry><type>int2[]</type></entry>

View File

@ -983,6 +983,14 @@ ALTER TABLE distributors ADD CONSTRAINT zipchk CHECK (char_length(zipcode) = 5);
</programlisting>
</para>
<para>
To add a check constraint only to a table and not to its children:
<programlisting>
ALTER TABLE ONLY distributors ADD CONSTRAINT zipchk CHECK (char_length(zipcode) = 5);
</programlisting>
(The check constraint will not be inherited by future children, either.)
</para>
<para>
To remove a check constraint from a table and all its children:
<programlisting>