I am trying out functions and triggers int postgreSQL, however i am having a problem, when the function is triggered it is giving me an error
ERROR: control reached end of trigger procedure without RETURN
this particular procedure is only executing an insert into command so i do not see why it needs a return
this is the script:
CREATE OR REPLACE FUNCTION forest_aud_func() returns trigger as $tree_stamp$
BEGIN
insert into Audit values('k',124,'l');
END;
$tree_stamp$
LANGUAGE plpgsql;
create trigger forest_aud_ins after insert on forest
for each row execute procedure forest_aud_func()
insert into forest values('Blue',1600,'Malta','Health Ltd')
The error message tells you all. You need to do a RETURN from the trigger function:
CREATE OR REPLACE FUNCTION forest_aud_func() returns trigger as $tree_stamp$
BEGIN
insert into Audit values('k',124,'l');
return new;
END;
$tree_stamp$
LANGUAGE plpgsql;
From the manual:
A trigger function must return either NULL or a record/row value having exactly the structure of the table the trigger was fired for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With