I have an entity which can be attached to other entities. I want to prevent any updates to this, instead can have new entries. That way I can keep existing links intact, and add new entries
There is a status column (active/inactive) When an update is issued, I want to update only status of the row to inactive. And then insert the updated values as new row. Would appreciate if this can be done in a generic way, which would work for all tables, and we will just need to add the trigger calling a function.
Something like
create trigger prevent_update_trigger
before update on the_table
for each row execute procedure prevent_update_do_insert();
create or replace function prevent_update_do_insert()
returns trigger as
$$
begin
// Code to update it to INACTIVE
-- Insert the UPDATE row as new row
// Code to INSERT new row
-- do NOT proceed with original UPDATE
return null;
end;
$$
language plpgsql;