CREATE OR REPLACE FUNCTION file_object_last_update() RETURNS trigger AS
$$
 DECLARE
  otype TEXT;
 BEGIN
  UPDATE object SET last_updated = now() WHERE objectid = new.objectid RETURNING objecttypeid INTO otype;
  IF otype = 'structure'::TEXT THEN
    UPDATE structure SET last_updated = now() WHERE structure.id = new.objectid;
  END IF;
  RETURN NULL;
 END
$$ LANGUAGE plpgsql;

CREATE TRIGGER file_object_last_update_trigger AFTER UPDATE OF objectid ON file FOR EACH ROW EXECUTE PROCEDURE file_object_last_update();

