Guest User

Untitled

a guest
Nov 24th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. I want a partitioning table B coerent whith a condition on a boolean "value" on a mother table A.
  2. With my code i only realize coerence with insert and delete events. It do not manage update events.
  3. When i update a the boolen "value" to true on the mother table on a record i want that this record is passed to the child table B, on other case
  4. when i update a the boolen "value" to false on the mother table on a record i want that this record is deleted in the child table B.
  5. How can i procede?
  6.  
  7.  
  8. My code
  9. create table B (
  10. primary key (id)
  11. check (value=true)
  12. check (value is not null)
  13. ) inherits (A);
  14.  
  15.  
  16.  
  17. CREATE or Replace function A_insert_procedure() returns trigger as $$
  18. begin
  19. if(new.value=true) then
  20. insert into B values (new.*);
  21. return null;
  22. else
  23. return new;
  24. end if;
  25. end;
  26. $$
  27. LAnguage plpgsql;
  28.  
  29. CREATE TRIGGER insert_trigger BEFORE INSERT ON A FOR EACH ROW EXECUTE PROCEDURE A_insert_procedure()
  30. Thanks
Add Comment
Please, Sign In to add comment