Re: Detecting whether a point is in a box.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: HST <helenst(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Detecting whether a point is in a box.
Date: 2007-08-27 22:58:47
Message-ID: 10049.1188255527@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

HST <helenst(at)gmail(dot)com> writes:
> I am trying to write a query to find all points that fall within a
> given box. However, I cannot seem to find the functionality for
> determining whether a point is within a box.

> e.g. select box '((0,0),(1,1))' @> point '(0.5,0.5)';

> operator does not exist: box @> point

psql's \do shows that we have box @> box and polygon @> point,
but no box @> point. So one possibility is to change your
box data to polygons. Another is to manufacture a zero-area
box from the point, using the box(point,point) function, and
use @> with that. Also, there is a point <@ box, although
I'm not sure you want to use that --- the lack of a commutator
suggests that it probably hasn't got any index support.

Is this just for a one-shot query, or are you hoping to do
indexed searches in a big table? If the latter, which object
is being stored in the table? You want to be sure you can
create an index that will support the operator you use.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Trent Shipley 2007-08-27 22:59:52 Re: Bigtime scaling of Postgresql (cluster and stuff I suppose)
Previous Message Scott Marlowe 2007-08-27 22:48:58 Re: Tables dissapearing