Advertisement
lord_long_phalles

sql rubbish

Dec 4th, 2020
1,101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. insert into main_information values
  3. (3, 'Christopher Powell', 'NYC(xxx)', 8, 'Subaru', 'Impreza WRX STI 2006', '2006-05-07', null, null, null, null, null, null);
  4.  
  5. create function instead_of_main_view() returns trigger as $$
  6. declare
  7.     for_split_1 text;
  8.     for_split_2 text;
  9. begin
  10.     if (old.owner_id <> any(select id from owner)) then
  11.         insert into owner values (new.owner_id, new.fio, new.adress);
  12.     end if;
  13.     if (old.creator <> any(select description from brands)) then
  14.         insert into brands (description) values (new.creator);
  15.     end if;
  16.     insert into auto values (new.auto_id, new.owner_id, new.creator, new.model, new.creation_date);
  17.     if (old.task_id <> null and old.task_id) then
  18.         insert into task values (new.task_id, new.auto_id, new.start_date, new.end_date, new.cost, new.description);
  19.     end if;
  20.     if (new.worker_id::int <> any(select id from worker) and new.worker_id <> null) then
  21.         for_split_1 = SPLIT_PART(new.worker_fio, ' ', 1);
  22.         for_split_2 = SPLIT_PART(new.worker_fio, ' ', 2);
  23.         insert into worker values (new.worker_id, for_split_1, for_split_2);
  24.     end if;
  25.     if (new.task_id <> null and new.worker_id <> null) then
  26.         insert into current_task values (new.worker_id, new.task_id);
  27.     end if;
  28.     return old;
  29. end;
  30. $$
  31. language plpgsql;
  32.  
  33.  
  34. create trigger insert_trigger_main_view
  35. instead of insert on main_information
  36. for each row execute procedure instead_of_main_view();
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement