CREATE OR REPLACE FUNCTION update_timestamp() RETURNS trigger AS $$
 DECLARE
  otype TEXT;
 BEGIN
  UPDATE object SET last_updated = now() WHERE object.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;

DROP TRIGGER update_timestamp_trigger ON data;
CREATE TRIGGER update_timestamp_trigger AFTER INSERT ON data FOR EACH ROW EXECUTE PROCEDURE update_timestamp();

