Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- insert into main_information values
- (3, 'Christopher Powell', 'NYC(xxx)', 8, 'Subaru', 'Impreza WRX STI 2006', '2006-05-07', null, null, null, null, null, null);
- create function instead_of_main_view() returns trigger as $$
- declare
- for_split_1 text;
- for_split_2 text;
- begin
- if (old.owner_id <> any(select id from owner)) then
- insert into owner values (new.owner_id, new.fio, new.adress);
- end if;
- if (old.creator <> any(select description from brands)) then
- insert into brands (description) values (new.creator);
- end if;
- insert into auto values (new.auto_id, new.owner_id, new.creator, new.model, new.creation_date);
- if (old.task_id <> null and old.task_id) then
- insert into task values (new.task_id, new.auto_id, new.start_date, new.end_date, new.cost, new.description);
- end if;
- if (new.worker_id::int <> any(select id from worker) and new.worker_id <> null) then
- for_split_1 = SPLIT_PART(new.worker_fio, ' ', 1);
- for_split_2 = SPLIT_PART(new.worker_fio, ' ', 2);
- insert into worker values (new.worker_id, for_split_1, for_split_2);
- end if;
- if (new.task_id <> null and new.worker_id <> null) then
- insert into current_task values (new.worker_id, new.task_id);
- end if;
- return old;
- end;
- $$
- language plpgsql;
- create trigger insert_trigger_main_view
- instead of insert on main_information
- for each row execute procedure instead_of_main_view();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement