|
1 | 1 | \set VERBOSITY terse
|
2 | 2 | CREATE EXTENSION pg_pathman;
|
| 3 | +/* |
| 4 | + * Test COPY |
| 5 | + */ |
3 | 6 | CREATE SCHEMA copy_stmt_hooking;
|
4 | 7 | CREATE TABLE copy_stmt_hooking.test(
|
5 | 8 | val int not null,
|
@@ -190,4 +193,92 @@ SELECT * FROM copy_stmt_hooking.test ORDER BY val;
|
190 | 193 |
|
191 | 194 | DROP SCHEMA copy_stmt_hooking CASCADE;
|
192 | 195 | NOTICE: drop cascades to 7 other objects
|
| 196 | +/* |
| 197 | + * Test auto check constraint renaming |
| 198 | + */ |
| 199 | +CREATE SCHEMA rename; |
| 200 | +CREATE TABLE rename.test(a serial, b int); |
| 201 | +SELECT create_hash_partitions('rename.test', 'a', 3); |
| 202 | + create_hash_partitions |
| 203 | +------------------------ |
| 204 | + 3 |
| 205 | +(1 row) |
| 206 | + |
| 207 | +ALTER TABLE rename.test_0 RENAME TO test_one; |
| 208 | +/* We expect to find check constraint renamed as well */ |
| 209 | +\d+ rename.test_one |
| 210 | + Table "rename.test_one" |
| 211 | + Column | Type | Modifiers | Storage | Stats target | Description |
| 212 | +--------+---------+---------------------------------------------------------+---------+--------------+------------- |
| 213 | + a | integer | not null default nextval('rename.test_a_seq'::regclass) | plain | | |
| 214 | + b | integer | | plain | | |
| 215 | +Check constraints: |
| 216 | + "pathman_test_one_1_check" CHECK (get_hash_part_idx(hashint4(a), 3) = 0) |
| 217 | +Inherits: rename.test |
| 218 | + |
| 219 | +/* Generates check constraint for relation */ |
| 220 | +CREATE OR REPLACE FUNCTION add_constraint(rel regclass, att text) |
| 221 | +RETURNS VOID AS $$ |
| 222 | +declare |
| 223 | +constraint_name text := build_check_constraint_name(rel, 'a'); |
| 224 | +BEGIN |
| 225 | +EXECUTE format('ALTER TABLE %s ADD CONSTRAINT %s CHECK (a < 100);', |
| 226 | + rel, constraint_name); |
| 227 | +END |
| 228 | +$$ |
| 229 | +LANGUAGE plpgsql; |
| 230 | +/* |
| 231 | + * Check that it doesn't affect regular inherited |
| 232 | + * tables that aren't managed by pg_pathman |
| 233 | + */ |
| 234 | +CREATE TABLE rename.test_inh (LIKE rename.test INCLUDING ALL); |
| 235 | +CREATE TABLE rename.test_inh_1 (LIKE rename.test INCLUDING ALL); |
| 236 | +ALTER TABLE rename.test_inh_1 INHERIT rename.test_inh; |
| 237 | +SELECT add_constraint('rename.test_inh_1', 'a'); |
| 238 | + add_constraint |
| 239 | +---------------- |
| 240 | + |
| 241 | +(1 row) |
| 242 | + |
| 243 | +ALTER TABLE rename.test_inh_1 RENAME TO test_inh_one; |
| 244 | +\d+ rename.test_inh_one |
| 245 | + Table "rename.test_inh_one" |
| 246 | + Column | Type | Modifiers | Storage | Stats target | Description |
| 247 | +--------+---------+---------------------------------------------------------+---------+--------------+------------- |
| 248 | + a | integer | not null default nextval('rename.test_a_seq'::regclass) | plain | | |
| 249 | + b | integer | | plain | | |
| 250 | +Check constraints: |
| 251 | + "pathman_test_inh_1_1_check" CHECK (a < 100) |
| 252 | +Inherits: rename.test_inh |
| 253 | + |
| 254 | +/* Check that plain tables are not affected too */ |
| 255 | +CREATE TABLE rename.plain_test(a serial, b int); |
| 256 | +ALTER TABLE rename.plain_test RENAME TO plain_test_renamed; |
| 257 | +SELECT add_constraint('rename.plain_test_renamed', 'a'); |
| 258 | + add_constraint |
| 259 | +---------------- |
| 260 | + |
| 261 | +(1 row) |
| 262 | + |
| 263 | +\d+ rename.plain_test_renamed |
| 264 | + Table "rename.plain_test_renamed" |
| 265 | + Column | Type | Modifiers | Storage | Stats target | Description |
| 266 | +--------+---------+---------------------------------------------------------------+---------+--------------+------------- |
| 267 | + a | integer | not null default nextval('rename.plain_test_a_seq'::regclass) | plain | | |
| 268 | + b | integer | | plain | | |
| 269 | +Check constraints: |
| 270 | + "pathman_plain_test_renamed_1_check" CHECK (a < 100) |
| 271 | + |
| 272 | +ALTER TABLE rename.plain_test_renamed RENAME TO plain_test; |
| 273 | +\d+ rename.plain_test |
| 274 | + Table "rename.plain_test" |
| 275 | + Column | Type | Modifiers | Storage | Stats target | Description |
| 276 | +--------+---------+---------------------------------------------------------------+---------+--------------+------------- |
| 277 | + a | integer | not null default nextval('rename.plain_test_a_seq'::regclass) | plain | | |
| 278 | + b | integer | | plain | | |
| 279 | +Check constraints: |
| 280 | + "pathman_plain_test_renamed_1_check" CHECK (a < 100) |
| 281 | + |
| 282 | +DROP SCHEMA rename CASCADE; |
| 283 | +NOTICE: drop cascades to 7 other objects |
193 | 284 | DROP EXTENSION pg_pathman;
|