From: | Vince Carney <vincecarney(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | input out of error with haversine formula |
Date: | 2010-10-15 05:03:11 |
Message-ID: | AANLkTikxpbeR+oNHVVQ-fTnvutr+pGxMmP5N7Z7TJNEO@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
The following will return an input out of error as the acos() function
cannot be -1 <= x <= 1.
SELECT * FROM
(SELECT *, (3959 * acos(cos(radians(37.7438640)) *
cos(radians(37.7438640)) * cos(radians(-97.4631299) -
radians(-97.4631299)) + sin(radians(37.7438640)) *
sin(radians(37.7438640))))
AS distance
FROM foo) AS distances
WHERE distance < 10
ORDER BY distance
If I break this down the following returns 1:
SELECT (cos(radians(37.7438640)) * cos(radians(37.7438640)) *
cos(radians(-97.4631299) - radians(-97.4631299)) + sin(radians(37.7438640))
* sin(radians(37.743864000)));
acos(1) would give me 0.
Thoughts or workaround suggestions?
Thanks.
--Vince--
From | Date | Subject | |
---|---|---|---|
Next Message | David Fetter | 2010-10-15 06:02:46 | Re: [GENERAL] pg_filedump binary for CentOS |
Previous Message | Guy Rouillier | 2010-10-15 04:27:26 | Re: It it possible to get this result in one query? |