mirror of
https://github.com/postgres/postgres.git
synced 2025-12-19 17:02:53 +03:00
Recast "ONLY" column CHECK constraints as NO INHERIT
The original syntax wasn't universally loved, and it didn't allow its
usage in CREATE TABLE, only ALTER TABLE. It now works everywhere, and
it also allows using ALTER TABLE ONLY to add an uninherited CHECK
constraint, per discussion.
The pg_constraint column has accordingly been renamed connoinherit.
This commit partly reverts some of the changes in
61d81bd28d, particularly some pg_dump and
psql bits, because now pg_get_constraintdef includes the necessary NO
INHERIT within the constraint definition.
Author: Nikhil Sontakke
Some tweaks by me
This commit is contained in:
@@ -907,7 +907,8 @@ ALTER TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceable>
|
||||
and <literal>TABLESPACE</> actions never recurse to descendant tables;
|
||||
that is, they always act as though <literal>ONLY</> were specified.
|
||||
Adding a constraint can recurse only for <literal>CHECK</> constraints,
|
||||
and is required to do so for such constraints.
|
||||
and is required to do so for such constraints, except those that are
|
||||
explicitely marked <literal>NO INHERIT</>.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
@@ -1013,7 +1014,7 @@ ALTER TABLE distributors ADD CONSTRAINT zipchk CHECK (char_length(zipcode) = 5);
|
||||
<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);
|
||||
ALTER TABLE distributors ADD CONSTRAINT zipchk CHECK NO INHERIT (char_length(zipcode) = 5);
|
||||
</programlisting>
|
||||
(The check constraint will not be inherited by future children, either.)
|
||||
</para>
|
||||
|
||||
Reference in New Issue
Block a user