DROP TRIGGER screen_details_modified ON screen_details;

CREATE TRIGGER screen_details_modified
  AFTER INSERT OR UPDATE OR DELETE
  ON screen_details
  FOR EACH ROW
  EXECUTE PROCEDURE screen_update();


CREATE OR REPLACE FUNCTION screen_update()
  RETURNS trigger AS
$BODY$
BEGIN
	IF TG_OP = 'INSERT' OR TG_OP = 'UPDATE'	THEN
		UPDATE screens SET is_published = false WHERE id = NEW.screen_id;
	ELSIF TG_OP = 'DELETE' THEN 
		UPDATE screens SET is_published = false WHERE id = OLD.screen_id;
	END IF;
	RETURN NULL;
END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION screen_update()
  OWNER TO postgres;