0

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;
Jebil
  • 1,144
  • 13
  • 25
  • What is wrong with the [answer you accepted](https://dba.stackexchange.com/a/242742/1822) on dba.stackexchange.com? –  Jul 15 '19 at 13:37
  • I couldnt complete my requirement from there, thats the reason @a_horse_with_no_name – Jebil Jul 15 '19 at 13:39
  • And I thought of re asking here, to get more eyes maybe. – Jebil Jul 15 '19 at 13:41

0 Answers0