Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I want a partitioning table B coerent whith a condition on a boolean "value" on a mother table A.
- With my code i only realize coerence with insert and delete events. It do not manage update events.
- 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
- 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.
- How can i procede?
- My code
- create table B (
- primary key (id)
- check (value=true)
- check (value is not null)
- ) inherits (A);
- CREATE or Replace function A_insert_procedure() returns trigger as $$
- begin
- if(new.value=true) then
- insert into B values (new.*);
- return null;
- else
- return new;
- end if;
- end;
- $$
- LAnguage plpgsql;
- CREATE TRIGGER insert_trigger BEFORE INSERT ON A FOR EACH ROW EXECUTE PROCEDURE A_insert_procedure()
- Thanks
Add Comment
Please, Sign In to add comment