Skip to main content
5 of 6
added 181 characters in body
Sean
  • 4.2k
  • 20
  • 24

You don't give any information about your tables. Assuming the point isn't in a table and venues has fields id, radius, geom...

select
   venue.id
from
   venue
where
   st_dwithin(
            st_geographyfromtext( 'POINT(' || venues.longitude || ' ' || venues.latitude || ')'),
            'POINT(0 0)'::geography,
            venues.radius)

This goes through the venues table and

  • reads the point geometry stored for the venue in venues.geom,
  • and tests whether the POINT(0 0) is within venues.radius meters from the venue.

It returns the venue.id if they intersect.

There might be a more elegant way to construct the geography from the long/lat.

I recommend playing with SpatiaLite to learn about the basic geometry operations. It's easier to set up and get going than PostGIS. They have a nice tutorial, too. Most of the functions are the same if only named differently.

Sean
  • 4.2k
  • 20
  • 24