diff options
author | Álvaro Herrera <alvherre@alvh.no-ip.org> | 2025-03-05 13:50:22 +0100 |
---|---|---|
committer | Álvaro Herrera <alvherre@alvh.no-ip.org> | 2025-03-05 13:50:22 +0100 |
commit | f4e53e10b6ce0eedeb98caa4356facb47c7bb9cb (patch) | |
tree | 9c45e19d7e8635cdb44a4279c3fa0164082c2c02 /src/backend/parser/gram.y | |
parent | f4694e0f35b218238cbc87bcf8f8f5c6639bb1d4 (diff) | |
download | postgresql-f4e53e10b6ce0eedeb98caa4356facb47c7bb9cb.tar.gz postgresql-f4e53e10b6ce0eedeb98caa4356facb47c7bb9cb.zip |
Add ALTER TABLE ... ALTER CONSTRAINT ... SET [NO] INHERIT
This allows to redefine an existing non-inheritable constraint to be
inheritable, which allows to straighten up situations with NO INHERIT
constraints so that thay can become normal constraints without having to
re-verify existing data. For existing inheritance children this may
require creating additional constraints, if they don't exist already.
It also allows to do the opposite, if only for symmetry.
Author: Suraj Kharage <suraj.kharage@enterprisedb.com>
Reviewed-by: jian he <jian.universality@gmail.com>
Discussion: https://postgr.es/m/CAF1DzPVfOW6Kk=7SSh7LbneQDJWh=PbJrEC_Wkzc24tHOyQWGg@mail.gmail.com
Diffstat (limited to 'src/backend/parser/gram.y')
-rw-r--r-- | src/backend/parser/gram.y | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index c11a3beff06..271ae26cbaf 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -2669,6 +2669,34 @@ alter_table_cmd: NULL, NULL, NULL, yyscanner); $$ = (Node *) n; } + /* ALTER TABLE <name> ALTER CONSTRAINT SET INHERIT */ + | ALTER CONSTRAINT name SET INHERIT + { + AlterTableCmd *n = makeNode(AlterTableCmd); + ATAlterConstraint *c = makeNode(ATAlterConstraint); + + n->subtype = AT_AlterConstraint; + n->def = (Node *) c; + c->conname = $3; + c->alterInheritability = true; + c->noinherit = false; + + $$ = (Node *) n; + } + /* ALTER TABLE <name> ALTER CONSTRAINT SET NO INHERIT */ + | ALTER CONSTRAINT name SET NO INHERIT + { + AlterTableCmd *n = makeNode(AlterTableCmd); + ATAlterConstraint *c = makeNode(ATAlterConstraint); + + n->subtype = AT_AlterConstraint; + n->def = (Node *) c; + c->conname = $3; + c->alterInheritability = true; + c->noinherit = true; + + $$ = (Node *) n; + } /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */ | VALIDATE CONSTRAINT name { |