 BEGIN
   SELECT srid INTO schema_srid FROM spatial_ref_sys WHERE srid = $1;
 
-  IF schema_srid IS NULL
-  THEN
+  IF schema_srid IS NULL THEN
     RAISE EXCEPTION 'Table spatial_ref_sys does not contain the SRID %. Insert commands for missing SRIDs can be found at spatialreference.org', srsno;
     RETURN 'SRID not ok';
   END IF;

    PERFORM UpdateGeometrySRID($7, $1, $2, $4);
  END IF;

  IF idx_name IS NOT NULL
  THEN
    -- recreate spatial index again
    IF $3 < 3
    THEN
      EXECUTE format('CREATE INDEX %I ON %I.%I USING GIST (%I)', idx_name, $7, $1, $2);
    ELSE
      EXECUTE format('CREATE INDEX %I ON %I.%I USING GIST (%I gist_geometry_ops_nd )', idx_name, $7, $1, $2);
    END IF;
  END IF;
END;
$$

  ) RETURNS GEOMETRY AS
$$
BEGIN
  IF geom IS NOT NULL THEN
    RETURN ST_Transform($1, $2);
  ELSE
    RETURN NULL;
