postgreSql创建自定义函数

1.求两个经纬度点之间的距离(米)

create or replace function st_distance3857(geom1 geometry,geom2 geometry) returns float as $$
  select 
      st_distance(
	st_transform(geom1,3857),
	st_transform(geom2,3857)
      ) ::float;
$$ language sql immutable strict;

//或者以下定义方式

create or replace function st_distance3857( geometry, geometry) returns float as $$
  select 
      st_distance(
	st_transform($1,3857),
	st_transform$2,3857)
      ) ::float;
$$ language sql immutable strict;

 

你可能感兴趣的:(PostgreSQL,Sql)