|
| 1 | +\set VERBOSITY terse |
| 2 | +SET search_path = 'public'; |
| 3 | +CREATE EXTENSION pg_pathman; |
| 4 | +CREATE SCHEMA dropped_cols; |
| 5 | +/* |
| 6 | + * we should be able to manage tables with dropped columns |
| 7 | + */ |
| 8 | +create table test_range(a int, b int, key int not null); |
| 9 | +alter table test_range drop column a; |
| 10 | +select create_range_partitions('test_range', 'key', 1, 10, 2); |
| 11 | + create_range_partitions |
| 12 | +------------------------- |
| 13 | + 2 |
| 14 | +(1 row) |
| 15 | + |
| 16 | +alter table test_range drop column b; |
| 17 | +select prepend_range_partition('test_range'); |
| 18 | + prepend_range_partition |
| 19 | +------------------------- |
| 20 | + test_range_3 |
| 21 | +(1 row) |
| 22 | + |
| 23 | +select * from pathman_partition_list order by parent, partition; |
| 24 | + parent | partition | parttype | expr | range_min | range_max |
| 25 | +------------+--------------+----------+------+-----------+----------- |
| 26 | + test_range | test_range_1 | 2 | key | 1 | 11 |
| 27 | + test_range | test_range_2 | 2 | key | 11 | 21 |
| 28 | + test_range | test_range_3 | 2 | key | -9 | 1 |
| 29 | +(3 rows) |
| 30 | + |
| 31 | +select pg_get_constraintdef(oid, true) from pg_constraint where conname = 'pathman_test_range_1_check'; |
| 32 | + pg_get_constraintdef |
| 33 | +------------------------------- |
| 34 | + CHECK (key >= 1 AND key < 11) |
| 35 | +(1 row) |
| 36 | + |
| 37 | +select pg_get_constraintdef(oid, true) from pg_constraint where conname = 'pathman_test_range_3_check'; |
| 38 | + pg_get_constraintdef |
| 39 | +------------------------------------------ |
| 40 | + CHECK (key >= '-9'::integer AND key < 1) |
| 41 | +(1 row) |
| 42 | + |
| 43 | +drop table test_range cascade; |
| 44 | +NOTICE: drop cascades to 4 other objects |
| 45 | +create table test_hash(a int, b int, key int not null); |
| 46 | +alter table test_hash drop column a; |
| 47 | +select create_hash_partitions('test_hash', 'key', 3); |
| 48 | + create_hash_partitions |
| 49 | +------------------------ |
| 50 | + 3 |
| 51 | +(1 row) |
| 52 | + |
| 53 | +alter table test_hash drop column b; |
| 54 | +create table test_dummy (like test_hash); |
| 55 | +select replace_hash_partition('test_hash_2', 'test_dummy', true); |
| 56 | + replace_hash_partition |
| 57 | +------------------------ |
| 58 | + test_dummy |
| 59 | +(1 row) |
| 60 | + |
| 61 | +select * from pathman_partition_list order by parent, partition; |
| 62 | + parent | partition | parttype | expr | range_min | range_max |
| 63 | +-----------+-------------+----------+------+-----------+----------- |
| 64 | + test_hash | test_hash_0 | 1 | key | | |
| 65 | + test_hash | test_hash_1 | 1 | key | | |
| 66 | + test_hash | test_dummy | 1 | key | | |
| 67 | +(3 rows) |
| 68 | + |
| 69 | +select pg_get_constraintdef(oid, true) from pg_constraint where conname = 'pathman_test_hash_1_check'; |
| 70 | + pg_get_constraintdef |
| 71 | +------------------------------------------------- |
| 72 | + CHECK (get_hash_part_idx(hashint4(key), 3) = 1) |
| 73 | +(1 row) |
| 74 | + |
| 75 | +select pg_get_constraintdef(oid, true) from pg_constraint where conname = 'pathman_test_dummy_check'; |
| 76 | + pg_get_constraintdef |
| 77 | +------------------------------------------------- |
| 78 | + CHECK (get_hash_part_idx(hashint4(key), 3) = 2) |
| 79 | +(1 row) |
| 80 | + |
| 81 | +drop table test_hash cascade; |
| 82 | +NOTICE: drop cascades to 3 other objects |
| 83 | +DROP SCHEMA dropped_cols CASCADE; |
| 84 | +DROP EXTENSION pg_pathman; |
0 commit comments