summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorTom Lane2002-08-30 19:23:20 +0000
committerTom Lane2002-08-30 19:23:20 +0000
commite2d156fa6e8a72fe36b956ea12f2eb09c9320792 (patch)
tree5ad356c7ce82255f91a5ec6d36d911c2116f9f3e /src/test
parent96fd7192e7102f9cfc10415c614e3dec19a5227e (diff)
Add attisinherited column to pg_attribute; use it to guard against
column additions, deletions, and renames that would let a child table get out of sync with its parent. Patch by Alvaro Herrera, with some kibitzing by Tom Lane.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/alter_table.out31
-rw-r--r--src/test/regress/sql/alter_table.sql33
2 files changed, 64 insertions, 0 deletions
diff --git a/src/test/regress/expected/alter_table.out b/src/test/regress/expected/alter_table.out
index b02aba52d7..3cd121ad59 100644
--- a/src/test/regress/expected/alter_table.out
+++ b/src/test/regress/expected/alter_table.out
@@ -1023,3 +1023,34 @@ select * from test;
(3 rows)
drop table test;
+-- test inheritance
+create table dropColumn (a int, b int, e int);
+create table dropColumnChild (c int) inherits (dropColumn);
+create table dropColumnAnother (d int) inherits (dropColumnChild);
+-- these two should fail
+alter table dropColumnchild drop column a;
+ERROR: ALTER TABLE: Cannot drop inherited column "a"
+alter table only dropColumnChild drop column b;
+ERROR: ALTER TABLE: Cannot drop inherited column "b"
+-- these three should work
+alter table only dropColumn drop column e;
+alter table dropColumnChild drop column c;
+alter table dropColumn drop column a;
+create table renameColumn (a int);
+create table renameColumnChild (b int) inherits (renameColumn);
+create table renameColumnAnother (c int) inherits (renameColumnChild);
+-- these three should fail
+alter table renameColumnChild rename column a to d;
+ERROR: renameatt: inherited attribute "a" may not be renamed
+alter table only renameColumnChild rename column a to d;
+ERROR: Inherited attribute "a" must be renamed in child tables too
+alter table only renameColumn rename column a to d;
+ERROR: Inherited attribute "a" must be renamed in child tables too
+-- these should work
+alter table renameColumn rename column a to d;
+alter table renameColumnChild rename column b to a;
+-- this should work
+alter table renameColumn add column w int;
+-- this should fail
+alter table only renameColumn add column x int;
+ERROR: Attribute must be added to child tables too
diff --git a/src/test/regress/sql/alter_table.sql b/src/test/regress/sql/alter_table.sql
index 6eaae24fa8..a5b6bd8f03 100644
--- a/src/test/regress/sql/alter_table.sql
+++ b/src/test/regress/sql/alter_table.sql
@@ -731,3 +731,36 @@ copy test(b,c) from stdin;
select * from test;
drop table test;
+-- test inheritance
+
+create table dropColumn (a int, b int, e int);
+create table dropColumnChild (c int) inherits (dropColumn);
+create table dropColumnAnother (d int) inherits (dropColumnChild);
+
+-- these two should fail
+alter table dropColumnchild drop column a;
+alter table only dropColumnChild drop column b;
+
+-- these three should work
+alter table only dropColumn drop column e;
+alter table dropColumnChild drop column c;
+alter table dropColumn drop column a;
+
+create table renameColumn (a int);
+create table renameColumnChild (b int) inherits (renameColumn);
+create table renameColumnAnother (c int) inherits (renameColumnChild);
+
+-- these three should fail
+alter table renameColumnChild rename column a to d;
+alter table only renameColumnChild rename column a to d;
+alter table only renameColumn rename column a to d;
+
+-- these should work
+alter table renameColumn rename column a to d;
+alter table renameColumnChild rename column b to a;
+
+-- this should work
+alter table renameColumn add column w int;
+
+-- this should fail
+alter table only renameColumn add column x int;