pgsql-renameatt-multiple-inheritance.patch
text/x-patch
Filename: pgsql-renameatt-multiple-inheritance.patch
Type: text/x-patch
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: context
| File | + | − |
|---|---|---|
| src/backend/commands/tablecmds.c | 11 | 0 |
| src/test/regress/expected/inherit.out | 17 | 0 |
| src/test/regress/sql/inherit.sql | 14 | 0 |
Index: src/test/regress/sql/inherit.sql
===================================================================
*** src/test/regress/sql/inherit.sql (revision 2388)
--- src/test/regress/sql/inherit.sql (working copy)
*************** CREATE TABLE inh_error1 () INHERITS (t1,
*** 336,338 ****
--- 336,352 ----
CREATE TABLE inh_error2 (LIKE t4 INCLUDING STORAGE) INHERITS (t1);
DROP TABLE t1, t2, t3, t4, t12_storage, t12_comments, t1_inh, t13_inh, t13_like, t_all;
+
+ -- Test for renaming
+ CREATE TABLE t1 (a int, b int);
+ CREATE TABLE t2 (b int, c int);
+ CREATE TABLE t3 (d int) INHERITS(t1, t2);
+ ALTER TABLE t1 RENAME a TO x;
+ ALTER TABLE t1 RENAME b TO y; -- to be failed
+ ALTER TABLE t3 RENAME d TO z;
+ SELECT * FROM t3;
+ DROP TABLE t3;
+ DROP TABLE t2;
+ DROP TABLE t1;
+
+
Index: src/test/regress/expected/inherit.out
===================================================================
*** src/test/regress/expected/inherit.out (revision 2388)
--- src/test/regress/expected/inherit.out (working copy)
*************** NOTICE: merging column "a" with inherit
*** 1057,1059 ****
--- 1057,1076 ----
ERROR: column "a" has a storage parameter conflict
DETAIL: MAIN versus EXTENDED
DROP TABLE t1, t2, t3, t4, t12_storage, t12_comments, t1_inh, t13_inh, t13_like, t_all;
+ -- Test for renaming
+ CREATE TABLE t1 (a int, b int);
+ CREATE TABLE t2 (b int, c int);
+ CREATE TABLE t3 (d int) INHERITS(t1, t2);
+ NOTICE: merging multiple inherited definitions of column "b"
+ ALTER TABLE t1 RENAME a TO x;
+ ALTER TABLE t1 RENAME b TO y; -- to be failed
+ ERROR: cannot rename multiple inherited column "b"
+ ALTER TABLE t3 RENAME d TO z;
+ SELECT * FROM t3;
+ x | b | c | z
+ ---+---+---+---
+ (0 rows)
+
+ DROP TABLE t3;
+ DROP TABLE t2;
+ DROP TABLE t1;
Index: src/backend/commands/tablecmds.c
===================================================================
*** src/backend/commands/tablecmds.c (revision 2388)
--- src/backend/commands/tablecmds.c (working copy)
*************** renameatt(Oid myrelid,
*** 2024,2029 ****
--- 2024,2040 ----
errmsg("cannot rename inherited column \"%s\"",
oldattname)));
+ /*
+ * If the attribute is inherited from multiple parents, forbid
+ * the renaming, because we don't have any reasonable way to keep
+ * integrity in whole of the inheritance relationship.
+ */
+ if (attform->attinhcount > 1)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
+ (errmsg("cannot rename multiple inherited column \"%s\"",
+ oldattname))));
+
/* should not already exist */
/* this test is deliberately not attisdropped-aware */
if (SearchSysCacheExists(ATTNAME,