check-no-inherit.patch
application/octet-stream
Filename: check-no-inherit.patch
Type: application/octet-stream
Part: 0
Message:
Re: CHECK NO INHERIT syntax
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
| File | + | − |
|---|---|---|
| src/backend/commands/typecmds.c | 7 | 1 |
| src/backend/parser/gram.y | 6 | 6 |
| src/backend/utils/adt/ruleutils.c | 3 | 4 |
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c
index 30850b2..353043d 100644
--- a/src/backend/commands/typecmds.c
+++ b/src/backend/commands/typecmds.c
@@ -921,8 +921,14 @@ DefineDomain(CreateDomainStmt *stmt)
/*
* Check constraints are handled after domain creation, as
- * they require the Oid of the domain
+ * they require the Oid of the domain; at this point we can
+ * only check that they're not marked NO INHERIT, because
+ * that would be bogus.
*/
+ if (constr->is_no_inherit)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+ errmsg("CHECK constraints for domains cannot be marked NO INHERIT")));
break;
/*
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 777da11..a84fb63 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -2709,13 +2709,13 @@ ColConstraintElem:
n->indexspace = $4;
$$ = (Node *)n;
}
- | CHECK opt_no_inherit '(' a_expr ')'
+ | CHECK '(' a_expr ')' opt_no_inherit
{
Constraint *n = makeNode(Constraint);
n->contype = CONSTR_CHECK;
n->location = @1;
- n->is_no_inherit = $2;
- n->raw_expr = $4;
+ n->is_no_inherit = $5;
+ n->raw_expr = $3;
n->cooked_expr = NULL;
$$ = (Node *)n;
}
@@ -2835,13 +2835,13 @@ TableConstraint:
;
ConstraintElem:
- CHECK opt_no_inherit '(' a_expr ')' ConstraintAttributeSpec
+ CHECK '(' a_expr ')' opt_no_inherit ConstraintAttributeSpec
{
Constraint *n = makeNode(Constraint);
n->contype = CONSTR_CHECK;
n->location = @1;
- n->is_no_inherit = $2;
- n->raw_expr = $4;
+ n->is_no_inherit = $5;
+ n->raw_expr = $3;
n->cooked_expr = NULL;
processCASbits($6, @6, "CHECK",
NULL, NULL, &n->skip_validation,
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index ec93149..412dfe6 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -1343,10 +1343,9 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
* Note that simply checking for leading '(' and trailing ')'
* would NOT be good enough, consider "(x > 0) AND (y > 0)".
*/
- appendStringInfo(&buf, "CHECK %s(%s)",
- conForm->connoinherit ? "NO INHERIT " : "",
- consrc);
-
+ appendStringInfo(&buf, "CHECK (%s)%s",
+ consrc,
+ conForm->connoinherit ? " NO INHERIT" : "");
break;
}
case CONSTRAINT_TRIGGER: