我有一些字段分别是pid(主键),login,logout,interval_time,今天(current_date)
登录和注销数据类型为(无时区的时间)
这里的登录和注销数据数据例如10:00:45、12:45:12、07:32:02(不像14:32:12、18:65:78、23:51:00)< / p>
所以我不知道是晚上还是白天,或者是下午还是上午。
If someone login = 07:00:00 and logout = 11:00:00
again he/she login = 01:00:00
that means here interval_time will be 2 hours. Exactly how much time he/she was inactive.
create or replace function interval_time()
returns trigger as
$BODY$
begin
if new.login or new.logout then
if new.login then
update employee set interval_time = new.logout::time - login::time where pid = new.pid; -- employee is my table name;
return new;
end if;
end if;
end;
$BODY$
language plpgsql;
create trigger employee_changer
before update
on employee
for each row
execute procedure employee_change()
Please let me know if you have any question.
Any help would be appreciated.
Thanks.