"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