sql - On postgreSQL update trigger audit, original table updates fine, but multiple rows appear in the audit table. -


i have table trigger applied it, populates audit table if changes. created original table 2 fields:

create table events(     code serial8 not null,     event date not null,     ); 

and want trigger populate audit table whenever event date on first table updated:

create table audit(     date_log date,     time_log time,     userid char(20),     event_code int,      action_log text,     old_date date,     new_date date );  

the trigger function:

create or replace function auditing() returns trigger $$ begin     insert audit(date_log,time_log,userid,event_code,action_log,old_date,new_date)     select current_date,current_time,current_user,code,tg_op,old.event, new.event events;     return null; end; $$ language plpgsql; 

and set trigger this:

create trigger audit_dates after update of event on events each row execute procedure auditing(); 

the problem having whenever run update function such as:

update events set event = '2013-03-01' code = 1; 

the original table updates fine, table should audit this, generates 1 audit row each row original table had, if original table has 200 rows , update 1 of them, 200 new rows generated in audit table.

i trying think whether because created trigger for each row , @ same time have been reading docs on this , looks syntax need.

what right way 1 new row in audit table each time update original table?

you have select ... events in trigger, it's selecting events. can use simple insert ... values since new , old variables.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -