* ALTER TABLE DROP CONSTRAINT * * Like DROP COLUMN, we can't use the normal ALTER TABLE recursion mechanism. */
| 13467 | * Like DROP COLUMN, we can't use the normal ALTER TABLE recursion mechanism. |
| 13468 | */ |
| 13469 | static void |
| 13470 | ATExecDropConstraint(Relation rel, const char *constrName, |
| 13471 | DropBehavior behavior, |
| 13472 | bool recurse, bool recursing, |
| 13473 | bool missing_ok, LOCKMODE lockmode) |
| 13474 | { |
| 13475 | List *children; |
| 13476 | ListCell *child; |
| 13477 | Relation conrel; |
| 13478 | Form_pg_constraint con; |
| 13479 | SysScanDesc scan; |
| 13480 | ScanKeyData skey[3]; |
| 13481 | HeapTuple tuple; |
| 13482 | bool found = false; |
| 13483 | bool is_no_inherit_constraint = false; |
| 13484 | char contype; |
| 13485 | |
| 13486 | /* At top level, permission check was done in ATPrepCmd, else do it */ |
| 13487 | if (recursing) |
| 13488 | ATSimplePermissions(rel, ATT_TABLE | ATT_FOREIGN_TABLE); |
| 13489 | |
| 13490 | conrel = table_open(ConstraintRelationId, RowExclusiveLock); |
| 13491 | |
| 13492 | /* |
| 13493 | * Find and drop the target constraint |
| 13494 | */ |
| 13495 | ScanKeyInit(&skey[0], |
| 13496 | Anum_pg_constraint_conrelid, |
| 13497 | BTEqualStrategyNumber, F_OIDEQ, |
| 13498 | ObjectIdGetDatum(RelationGetRelid(rel))); |
| 13499 | ScanKeyInit(&skey[1], |
| 13500 | Anum_pg_constraint_contypid, |
| 13501 | BTEqualStrategyNumber, F_OIDEQ, |
| 13502 | ObjectIdGetDatum(InvalidOid)); |
| 13503 | ScanKeyInit(&skey[2], |
| 13504 | Anum_pg_constraint_conname, |
| 13505 | BTEqualStrategyNumber, F_NAMEEQ, |
| 13506 | CStringGetDatum(constrName)); |
| 13507 | scan = systable_beginscan(conrel, ConstraintRelidTypidNameIndexId, |
| 13508 | true, NULL, 3, skey); |
| 13509 | |
| 13510 | /* There can be at most one matching row */ |
| 13511 | if (HeapTupleIsValid(tuple = systable_getnext(scan))) |
| 13512 | { |
| 13513 | ObjectAddress conobj; |
| 13514 | |
| 13515 | con = (Form_pg_constraint) GETSTRUCT(tuple); |
| 13516 | |
| 13517 | /* Don't drop inherited constraints */ |
| 13518 | if (con->coninhcount > 0 && !recursing) |
| 13519 | ereport(ERROR, |
| 13520 | (errcode(ERRCODE_INVALID_TABLE_DEFINITION), |
| 13521 | errmsg("cannot drop inherited constraint \"%s\" of relation \"%s\"", |
| 13522 | constrName, RelationGetRelationName(rel)))); |
| 13523 | |
| 13524 | is_no_inherit_constraint = con->connoinherit; |
| 13525 | contype = con->contype; |
| 13526 |
no test coverage detected