Update trigger on postgresql -


i new postgresql , i'm trying create trigger on update. have 2 tables source , destination same table structure. want records updated on destination when there update on source. tried below trigger function:

  create function ins_functiontest() returns trigger ' begin  if tg_op = ''update''      insert  destination(id,name,tg_op)      values (new.id,new.name, tg_op);       return new;   end if; end ' language plpgsql; 

column 'id' primary key on both tables above function fails when there update on source record exists on destination.

i tried modify function update rest of columns in table comparing id fields on source , destination.

 update des       set name = new.name,tg_op= update       destination des join source src       on des.id = src.id       des.id = src.id 

but couldn't syntax correct. appreciated.

i'm using postgresql 8.4.

i figured out solution problem, below answer. create function ins_functiontest() returns trigger ' begin if tg_op = ''update'' update destination_table_name set name = new.name, id = new.id;

end if; end ' language plpgsql;


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -