Listing 3:  trigger functions


-- Function: auth_prune()
CREATE FUNCTION auth_prune() RETURNS opaque AS '
    BEGIN
        delete from auth where sourceip = NEW.sourceip;
        RETURN NEW;
    END;
'  LANGUAGE 'plpgsql';


- Function: traffic_username()
CREATE FUNCTION traffic_username() RETURNS opaque AS '
    BEGIN
        IF NEW.username ISNULL THEN

                NEW.username := (

                        select distinct auth.username 

                        from  auth

                        where  NEW.sourceip = auth.sourceip
                        );

        END IF;
       RETURN NEW;
    END;
'  LANGUAGE 'plpgsql';

