@@ -1283,6 +1283,115 @@ order by 1, 2;
1283
1283
1284
1284
drop table p1 cascade;
1285
1285
NOTICE: drop cascades to table p1_c1
1286
+ --
1287
+ -- Test DROP behavior of multiply-defined CHECK constraints
1288
+ --
1289
+ create table p1(f1 int constraint f1_pos CHECK (f1 > 0));
1290
+ create table p1_c1 (f1 int constraint f1_pos CHECK (f1 > 0)) inherits (p1);
1291
+ NOTICE: merging column "f1" with inherited definition
1292
+ NOTICE: merging constraint "f1_pos" with inherited definition
1293
+ alter table p1_c1 drop constraint f1_pos;
1294
+ ERROR: cannot drop inherited constraint "f1_pos" of relation "p1_c1"
1295
+ alter table p1 drop constraint f1_pos;
1296
+ \d p1_c1
1297
+ Table "public.p1_c1"
1298
+ Column | Type | Collation | Nullable | Default
1299
+ --------+---------+-----------+----------+---------
1300
+ f1 | integer | | |
1301
+ Check constraints:
1302
+ "f1_pos" CHECK (f1 > 0)
1303
+ Inherits: p1
1304
+
1305
+ drop table p1 cascade;
1306
+ NOTICE: drop cascades to table p1_c1
1307
+ create table p1(f1 int constraint f1_pos CHECK (f1 > 0));
1308
+ create table p2(f1 int constraint f1_pos CHECK (f1 > 0));
1309
+ create table p1p2_c1 (f1 int) inherits (p1, p2);
1310
+ NOTICE: merging multiple inherited definitions of column "f1"
1311
+ NOTICE: merging column "f1" with inherited definition
1312
+ create table p1p2_c2 (f1 int constraint f1_pos CHECK (f1 > 0)) inherits (p1, p2);
1313
+ NOTICE: merging multiple inherited definitions of column "f1"
1314
+ NOTICE: merging column "f1" with inherited definition
1315
+ NOTICE: merging constraint "f1_pos" with inherited definition
1316
+ alter table p2 drop constraint f1_pos;
1317
+ alter table p1 drop constraint f1_pos;
1318
+ \d p1p2_c*
1319
+ Table "public.p1p2_c1"
1320
+ Column | Type | Collation | Nullable | Default
1321
+ --------+---------+-----------+----------+---------
1322
+ f1 | integer | | |
1323
+ Inherits: p1,
1324
+ p2
1325
+
1326
+ Table "public.p1p2_c2"
1327
+ Column | Type | Collation | Nullable | Default
1328
+ --------+---------+-----------+----------+---------
1329
+ f1 | integer | | |
1330
+ Check constraints:
1331
+ "f1_pos" CHECK (f1 > 0)
1332
+ Inherits: p1,
1333
+ p2
1334
+
1335
+ drop table p1, p2 cascade;
1336
+ NOTICE: drop cascades to 2 other objects
1337
+ DETAIL: drop cascades to table p1p2_c1
1338
+ drop cascades to table p1p2_c2
1339
+ create table p1(f1 int constraint f1_pos CHECK (f1 > 0));
1340
+ create table p1_c1() inherits (p1);
1341
+ create table p1_c2() inherits (p1);
1342
+ create table p1_c1c2() inherits (p1_c1, p1_c2);
1343
+ NOTICE: merging multiple inherited definitions of column "f1"
1344
+ \d p1_c1c2
1345
+ Table "public.p1_c1c2"
1346
+ Column | Type | Collation | Nullable | Default
1347
+ --------+---------+-----------+----------+---------
1348
+ f1 | integer | | |
1349
+ Check constraints:
1350
+ "f1_pos" CHECK (f1 > 0)
1351
+ Inherits: p1_c1,
1352
+ p1_c2
1353
+
1354
+ alter table p1 drop constraint f1_pos;
1355
+ \d p1_c1c2
1356
+ Table "public.p1_c1c2"
1357
+ Column | Type | Collation | Nullable | Default
1358
+ --------+---------+-----------+----------+---------
1359
+ f1 | integer | | |
1360
+ Inherits: p1_c1,
1361
+ p1_c2
1362
+
1363
+ drop table p1 cascade;
1364
+ NOTICE: drop cascades to 3 other objects
1365
+ DETAIL: drop cascades to table p1_c1
1366
+ drop cascades to table p1_c2
1367
+ drop cascades to table p1_c1c2
1368
+ create table p1(f1 int constraint f1_pos CHECK (f1 > 0));
1369
+ create table p1_c1() inherits (p1);
1370
+ create table p1_c2(constraint f1_pos CHECK (f1 > 0)) inherits (p1);
1371
+ NOTICE: merging constraint "f1_pos" with inherited definition
1372
+ create table p1_c1c2() inherits (p1_c1, p1_c2, p1);
1373
+ NOTICE: merging multiple inherited definitions of column "f1"
1374
+ NOTICE: merging multiple inherited definitions of column "f1"
1375
+ alter table p1_c2 drop constraint f1_pos;
1376
+ ERROR: cannot drop inherited constraint "f1_pos" of relation "p1_c2"
1377
+ alter table p1 drop constraint f1_pos;
1378
+ alter table p1_c1c2 drop constraint f1_pos;
1379
+ ERROR: cannot drop inherited constraint "f1_pos" of relation "p1_c1c2"
1380
+ alter table p1_c2 drop constraint f1_pos;
1381
+ \d p1_c1c2
1382
+ Table "public.p1_c1c2"
1383
+ Column | Type | Collation | Nullable | Default
1384
+ --------+---------+-----------+----------+---------
1385
+ f1 | integer | | |
1386
+ Inherits: p1_c1,
1387
+ p1_c2,
1388
+ p1
1389
+
1390
+ drop table p1 cascade;
1391
+ NOTICE: drop cascades to 3 other objects
1392
+ DETAIL: drop cascades to table p1_c1
1393
+ drop cascades to table p1_c2
1394
+ drop cascades to table p1_c1c2
1286
1395
-- Test that a valid child can have not-valid parent, but not vice versa
1287
1396
create table invalid_check_con(f1 int);
1288
1397
create table invalid_check_con_child() inherits(invalid_check_con);
0 commit comments