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

gcc - MinGW's ld cannot perform PE operations on non PE output file -

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

c# - Search and Add Comment with OpenXML for Word -