fixed proximity to endpoint query, works in postgres