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

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -