Re: "People near me" query - Mailing list pgsql-general

From Tom Lane
Subject Re: "People near me" query
Date
Msg-id 24093.1079708517@sss.pgh.pa.us
Whole thread Raw
In response to Re: "People near me" query  ("Bas Scheffers" <bas@scheffers.net>)
List pgsql-general
"Bas Scheffers" <bas@scheffers.net> writes:
> Once you have that, the rest is easy. create a column of the type "point"
> and store the grid coordinates in there. The just use the "contains"
> operator (~) in a query.
> (http://www.postgresql.org/docs/7.4/static/functions-geometry.html)

> Example:
> My coordinates are 523857,175349. So to find anyone living within 10KM of
> me, I just do "select * from people where '((523857,175349),10000)' ~
> location"

> Unfortunately, Postgres doesn't know how to index this.

You can index such queries using rtree indexes.  There was a discussion
of this with a full example just a couple weeks ago:
http://archives.postgresql.org/pgsql-novice/2004-03/msg00070.php

It's likely that PostGIS provides an even better solution, but I haven't
used it.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: sequential scan when using bigint value
Next
From: Tom Lane
Date:
Subject: Re: Index selection (and partial index) for BYTEA field