Menu

[3c04a4]: / sql / update_game_time.sql  Maximize  Restore  History

Download this file

25 lines (21 with data), 583 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
create or replace function update_game_time() returns trigger as
$BODY$
begin
if TG_OP = 'INSERT' then
if NEW.status = 'finished'::game_status then
NEW.played_date = current_timestamp;
end if;
elsif TG_OP = 'UPDATE' then
if OLD.status != NEW.status AND NEW.status = 'finished'::game_status then
NEW.played_date = current_timestamp;
end if;
end if;
return NEW;
end;
$BODY$ language 'plpgsql';
drop trigger if exists t_update_game_time on games;
create trigger t_update_game_time
before insert or update
on games
for each row
execute procedure update_game_time();