postgresql - Accessing row values in a trigger -


here code far:

create or replace function updatedegreestatus() returns trigger $updatedegreestatus$   begin     if(new.degreename = old.degreename , old.enddate = null)               update degree           set old.enddate = current_date           degree.degreeid = old.degreeid;     end if;     return new;     end;     $updatedegreestatus$ language plpgsql;  create trigger updatedegreestatus   before insert on degree   each row   execute procedure updatedegreestatus(); 

what having trouble accessing current values of row trigger on. how stored procedure should work, if new insert has same degree name current row , current row value end date null this. keyword old not how access current row values. , have been reading through documentation , still can not find answer. if has input on how fix issue, love help.

here current table:

enter image description here

and insert this:

insert degree(degreeid, degreename, type, startdate, enddate)     values(3, 'computer science concentration in software development', 'concentration', current_date, null) 

now want happen when insert command issued fire off trigger, , go , check if new degreename equals current row degreename , if current row enddate null. if issue update on current row, sets enddate current_date.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -