* Check if command can be executed with current replica identity. */
| 565 | * Check if command can be executed with current replica identity. |
| 566 | */ |
| 567 | void |
| 568 | CheckCmdReplicaIdentity(Relation rel, CmdType cmd) |
| 569 | { |
| 570 | PublicationActions *pubactions; |
| 571 | |
| 572 | /* We only need to do checks for UPDATE and DELETE. */ |
| 573 | if (cmd != CMD_UPDATE && cmd != CMD_DELETE) |
| 574 | return; |
| 575 | |
| 576 | /* If relation has replica identity we are always good. */ |
| 577 | if (rel->rd_rel->relreplident == REPLICA_IDENTITY_FULL || |
| 578 | OidIsValid(RelationGetReplicaIndex(rel))) |
| 579 | return; |
| 580 | |
| 581 | /* |
| 582 | * This is either UPDATE OR DELETE and there is no replica identity. |
| 583 | * |
| 584 | * Check if the table publishes UPDATES or DELETES. |
| 585 | */ |
| 586 | pubactions = GetRelationPublicationActions(rel); |
| 587 | if (cmd == CMD_UPDATE && pubactions->pubupdate) |
| 588 | ereport(ERROR, |
| 589 | (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), |
| 590 | errmsg("cannot update table \"%s\" because it does not have a replica identity and publishes updates", |
| 591 | RelationGetRelationName(rel)), |
| 592 | errhint("To enable updating the table, set REPLICA IDENTITY using ALTER TABLE."))); |
| 593 | else if (cmd == CMD_DELETE && pubactions->pubdelete) |
| 594 | ereport(ERROR, |
| 595 | (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), |
| 596 | errmsg("cannot delete from table \"%s\" because it does not have a replica identity and publishes deletes", |
| 597 | RelationGetRelationName(rel)), |
| 598 | errhint("To enable deleting from the table, set REPLICA IDENTITY using ALTER TABLE."))); |
| 599 | } |
| 600 | |
| 601 | |
| 602 | /* |
no test coverage detected