i am trying to create a trigger function in postgresql that should check records with the same id (i.e comparison by id with existing records) before inserting or updating the records,if the function finds records that have the same id, then that entry is set to be the time_dead(for example let me explain using this diagram below)

lets say i run a query
INSERT INTO persons (id, time_create, time_dead, First_name, Last_name)
 values (1, 'now();', ' ', 'sathiya', 'james');

i want to have a table like this below

id     time_create      time-dead            Name
1          06.12             Nil              henry   
2          07.12                              muka
id 1 had a time 06.12 which was the time_create the time at that moment but the time_dead is NULL,this is the same as id 2 but next time i try to run the insert query with same id but different names(i.e if id's are equal) i should get a table like this after run the select query,

id    time_create      time-dead           Name
  1     06.12              14.35           henry   
  2     07.12                                muka
  1     14.35                                waks

henry and waks have the same id which is 1,after running an insert query henry 's time_dead is equal to waks time_create so this should happen to entries with the same id if another entry was to made lets say james with id 1 the time entry for james will be equal to the time_dead for waks...i hope im clear.

this is what i have so far my function is like this but its not working

CREATE FUNCTION tr_function() RETURNS trigger AS '
  IF tg_op = ''UPDATE'' THEN
     UPDATE persons
     SET time_dead = NEW.time_create
         id = NEW.id
         AND time_dead IS NULL
  RETURN new;
' LANGUAGE plpgsql;
        ON persons FOR each ROW
        EXECUTE PROCEDURE tr_function();

and when i run this query its say time_dead is not supposed to be null,what am i supposed to do or is there a way i can write a trigger function that will autmatically enter the time upon inserting or updating but give me results like the above tables when i run a select query???

what wrong am i doing?