Re: haversine formula with postgreSQL

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: haversine formula with postgreSQL
Дата
Msg-id 4642.1253224069@sss.pgh.pa.us
обсуждение исходный текст
Ответ на haversine formula with postgreSQL  (Jonathan <jharahush@gmail.com>)
Ответы Re: haversine formula with postgreSQL  (Mike Christensen <mike@kitchenpc.com>)
Re: haversine formula with postgreSQL  (Rob Wultsch <wultsch@gmail.com>)
Список pgsql-general
Jonathan <jharahush@gmail.com> writes:
> Here is my PHP with SQL:
> $query = sprintf("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 dist LIMIT 0 OFFSET 20",

Sigh, you've been misled by MySQL's nonstandard behavior.  You cannot
refer to output columns of a query in its HAVING clause; it's disallowed
per spec and not logically sensible either.  The simplest way to deal
with it is just to repeat the expression in HAVING.  If you really
really don't want to write it twice, you can use a subquery.

            regards, tom lane

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Row estimates on empty table
Следующее
От: Martin Gainty
Дата:
Сообщение: Re: 'Weird' errors