CREATE OR REPLACE FUNCTION copy_structure_id() RETURNS trigger AS '
 BEGIN
  INSERT INTO object (objectid, objecttypeid) VALUES (new.id, ''structure'');
  RETURN NULL;
 END
' LANGUAGE plpgsql;

CREATE TRIGGER copy_structure_id_trigger AFTER INSERT ON structure FOR EACH ROW EXECUTE PROCEDURE copy_structure_id();

CREATE OR REPLACE FUNCTION delete_id() RETURNS trigger AS '
 BEGIN
  DELETE FROM object WHERE objectid = old.id;
  RETURN NULL;
 END
' LANGUAGE plpgsql;

CREATE TRIGGER delete_structure_id_trigger AFTER DELETE ON structure FOR EACH ROW EXECUTE PROCEDURE delete_id();

