Re: [GENERAL] haversine formula with postgreSQL

2009-09-19 Thread Tom Lane
Rob Wultsch writes: > On Thu, Sep 17, 2009 at 2:47 PM, Tom Lane wrote: >> Jonathan 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( longitu

Re: [GENERAL] haversine formula with postgreSQL

2009-09-19 Thread Rob Wultsch
On Thu, Sep 17, 2009 at 2:47 PM, Tom Lane wrote: > Jonathan 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') )

Re: [GENERAL] haversine formula with postgreSQL

2009-09-19 Thread Merlin Moncure
On Fri, Sep 18, 2009 at 5:50 PM, Scott Bailey wrote: >> And I think that might work for you.  The performance is going to be >> miserable for large stat sets, because it's going to scan the whole >> aaafacilities table every time and recompute every distance, but as an >> example goes it's probabl

Re: [GENERAL] haversine formula with postgreSQL

2009-09-18 Thread Scott Bailey
And I think that might work for you. The performance is going to be miserable for large stat sets, because it's going to scan the whole aaafacilities table every time and recompute every distance, but as an example goes it's probably acceptable. Something I did when implementing haversine in

Re: [GENERAL] haversine formula with postgreSQL

2009-09-18 Thread Greg Smith
On Thu, 17 Sep 2009, Jonathan wrote: Invalid query: ERROR: column "distance" does not exist LINE 1: ...ude ) ) ) ) AS distance FROM aaafacilities HAVING distance <... ^ You can't use distance in a HAVING clause if distance is computed as part of the query result. You can rewrite this to use

Re: [GENERAL] haversine formula with postgreSQL

2009-09-17 Thread Scott Marlowe
On Thu, Sep 17, 2009 at 8:37 PM, Jonathan Harahush wrote: > I do have PostGIS installed and I use it for other things (geoserver), but > I'm not knowledgeable enough about it to the point where I understand how to > get it to work with the Google Maps API.  I'll look into it.  In the > meantime, I

Re: [GENERAL] haversine formula with postgreSQL

2009-09-17 Thread Jonathan Harahush
I do have PostGIS installed and I use it for other things (geoserver), but I'm not knowledgeable enough about it to the point where I understand how to get it to work with the Google Maps API. I'll look into it. In the meantime, I was hoping to create something based off of the GMaps/PHP/MySQL ex

Re: [GENERAL] haversine formula with postgreSQL

2009-09-17 Thread Brent Wood
A bit out in left field, Writing your own haversine in Postgres seems a bit like reinventing a wooden wheel when you gan get a free pneumatic one... Any reason not to just install PostGIS & fully support geometries & projections in Postgres? You can build the geometries provided to the functio

Re: [GENERAL] haversine formula with postgreSQL

2009-09-17 Thread Tom Lane
Mike Christensen writes: > This behavior kinda gets me sometimes too, especially in WHERE clauses.. > I'm a bit curious as to why this is so bad. I could see why it would > be expensive to do, since your clause wouldn't be indexed - but why is > the syntax itself not allowed? It's not logically

Re: [GENERAL] haversine formula with postgreSQL

2009-09-17 Thread Jonathan
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

Re: [GENERAL] haversine formula with postgreSQL

2009-09-17 Thread Mike Christensen
This behavior kinda gets me sometimes too, especially in WHERE clauses.. I'm a bit curious as to why this is so bad. I could see why it would be expensive to do, since your clause wouldn't be indexed - but why is the syntax itself not allowed? Repeating the clause isn't gonna gain you any speed,

Re: [GENERAL] haversine formula with postgreSQL

2009-09-17 Thread Tom Lane
Jonathan 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

[GENERAL] haversine formula with postgreSQL

2009-09-17 Thread Jonathan
Hi! I am looking at the PHP/MySQL Google Maps API store locator example here: http://code.google.com/apis/maps/articles/phpsqlsearch.html And I'm trying to get this to work with PostgreSQL instead of MySQL. I've (slightly) modified the haversine formula part of my PHP script but I keep getting

Re: [GENERAL] haversine formula with postgreSQL

2009-09-17 Thread Scott Marlowe
On Thu, Sep 17, 2009 at 1:16 PM, Jonathan wrote: > Hi! > > I am looking at the PHP/MySQL Google Maps API store locator example > here: > > http://code.google.com/apis/maps/articles/phpsqlsearch.html > > And I'm trying to get this to work with PostgreSQL instead of MySQL. > > I've (slightly) modifi