CREATE OR REPLACE FUNCTION region_regiongroup_update() RETURNS trigger AS '
 BEGIN
  UPDATE region SET regiongroupid = regiontype.regiongroupid FROM regiontype WHERE regiontype.id = NEW.regiontypeid AND region.id = NEW.id;
  RETURN NULL;
 END
' LANGUAGE plpgsql;

CREATE TRIGGER region_regiongroup_update AFTER UPDATE OF regiontypeid ON region FOR EACH ROW EXECUTE PROCEDURE region_regiongroup_update();

