Re: Indexing a field of type point - Mailing list pgsql-sql

From Tom Lane
Subject Re: Indexing a field of type point
Date
Msg-id 17550.1186680807@sss.pgh.pa.us
Whole thread Raw
In response to Indexing a field of type point  (David Cottingham <david.cottingham@cl.cam.ac.uk>)
List pgsql-sql
David Cottingham <david.cottingham@cl.cam.ac.uk> writes:
> I have a table containing a field named location, of type point, i.e. a 
> position in two dimensions. The table has several million records in, and I 
> need to extract those records whose location value is contained within a 
> certain bounding box.

Given the standard opclasses, your best bet is to convert the point into
a zero-volume box or circle, eg
create index i on t using gist (circle(pointcol,0))

and then express queries as "circle(pointcol,0) overlaps target-box".

PostGIS might have something more nicely adapted ...
        regards, tom lane


pgsql-sql by date:

Previous
From: David Cottingham
Date:
Subject: Indexing a field of type point
Next
From: Andreas Joseph Krogh
Date:
Subject: PG won't use index on ORDER BY