在Postgres 9.1下面的代码会产生错误
ERROR: input is out of range
CONTEXT: SQL function "gc_dist1" statement 1
如何在9.1中修复它?
create or replace function gc_dist1(_lat1 float8, _lon1 float8, _lat2 float8, _lon2 float8)
returns float8 as $$
select ACOS(SIN(radians($1))*SIN(radians($3))+COS(radians($1))*COS(radians($3))*COS(radians($4)-radians($2)))*6371;
$$ language sql immutable;
select gc_dist1(24.6269989013672,59.3357849157094,24.6269989013672,59.3357849121094);
答案 0 :(得分:0)
如果失败,因为acos()
函数不能接受高于1的值。
在你的例子中就是这种情况。
SELECT (
SIN(radians(24.6269989013672))
* SIN(radians(24.6269989013672))
+ COS(radians(24.6269989013672))
* COS(radians(24.6269989013672))
* COS(radians(59.3357849121094)-radians(59.3357849157094))
) > 1 -- true
您的功能逻辑似乎不正确。