alttab-setnotnull-v1.patch
application/octet-stream
Filename: alttab-setnotnull-v1.patch
Type: application/octet-stream
Part: 0
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
Series: patch v1
| File | + | − |
|---|---|---|
| src/backend/catalog/index.c | 3 | 5 |
| src/test/regress/expected/alter_table.out | 1 | 1 |
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index d25b39bb54..4ebac27d10 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -185,6 +185,8 @@ relationHasPrimaryKey(Relation rel)
* created NOT NULL during CREATE TABLE), do an ALTER SET NOT NULL to mark
* them so --- or fail if they are not in fact nonnull.
*
+ * For ALTER TABLE, SET NOT NULL is applied as well to child tables.
+ *
* Caller had better have at least ShareLock on the table, else the not-null
* checking isn't trustworthy.
*/
@@ -253,17 +255,13 @@ index_check_primary_key(Relation heapRel,
}
/*
- * XXX: Shouldn't the ALTER TABLE .. SET NOT NULL cascade to child tables?
- * Currently, since the PRIMARY KEY itself doesn't cascade, we don't
- * cascade the notnull constraint(s) either; but this is pretty debatable.
- *
* XXX: possible future improvement: when being called from ALTER TABLE,
* it would be more efficient to merge this with the outer ALTER TABLE, so
* as to avoid two scans. But that seems to complicate DefineIndex's API
* unduly.
*/
if (cmds)
- AlterTableInternal(RelationGetRelid(heapRel), cmds, false);
+ AlterTableInternal(RelationGetRelid(heapRel), cmds, is_alter_table);
}
/*
diff --git a/src/test/regress/expected/alter_table.out b/src/test/regress/expected/alter_table.out
index 13d6a4b747..e9fd1aacce 100644
--- a/src/test/regress/expected/alter_table.out
+++ b/src/test/regress/expected/alter_table.out
@@ -328,7 +328,7 @@ Number of child tables: 1 (Use \d+ to list them.)
Table "public.constraint_rename_test2"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
- a | integer | | |
+ a | integer | | not null |
b | integer | | |
c | integer | | |
d | integer | | |