Re: haversine formula with postgreSQL

Поиск
Список
Период
Сортировка
От Jonathan
Тема Re: haversine formula with postgreSQL
Дата
Msg-id 1fc16f45-f2c0-4a56-96e0-5a649f92b25f@o21g2000vbl.googlegroups.com
обсуждение исходный текст
Ответ на haversine formula with postgreSQL  (Jonathan <jharahush@gmail.com>)
Список pgsql-general
It's the whole query as far as I can tell.  The app takes input from
the user --- the user enters an address and chooses a radius ("show me
all facilities within 5 miles of this address") and then the latitude
and longitude of the address and the radius is passed into the query
so that the database can grab all locations within a certain radius.

The example provided by Google is using MySQL.  The query for MySQL
looks like this:

SELECT address, name, lat, lng, ( 3959 * acos( cos( radians('%s') ) *
cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin
( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM markers
HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20

And I'm attempting to change it to work with Postgres and have done
this:

SELECT 'ID', 'FACILITY', 'ADDRESS', latitude, longitude, ( 3959 * acos
( cos( radians('%s') ) * cos( radians( latitude ) ) * cos( radians
( longitude ) - radians('%s') ) + sin( radians('%s') ) * sin( radians
( latitude ) ) ) ) AS distance FROM aaafacilities HAVING distance <
'%s' ORDER BY distance LIMIT 0 OFFSET 20


aaafacilities is my table name in my posgres database.

I'm sorry if this isn't enough info.. like I said, I'm new to this but
definitely interested in learning and figuring this out!

From what I can tell, the database is supposed to calculate and then
output the distance of each "match" but it seems like in the MySQL
example, it can do this without having an actual distance column in
the database.

Thanks again!

В списке pgsql-general по дате отправления:

Предыдущее
От: Mike Christensen
Дата:
Сообщение: Re: haversine formula with postgreSQL
Следующее
От: Tom Lane
Дата:
Сообщение: Re: haversine formula with postgreSQL