Distance Operations

The distance operator <-> for set and span types returns the smallest distance between the extents that bound the two values: the bounding span of a set, a span or a span set of numbers, dates or timestamps, and the bounding box of a set of geometries or geographies. A value lying between two elements of a set, or in a hole of a span set, is therefore at distance 0 from it. The bounding box of a set of geographies is read by its bounds, the region of its longitudes and latitudes, and never as the polygon of its corners, whose great-circle edges leave that region. The distance has the type of the difference of two values, as the PostgreSQL minus operator answers it: the base type for numbers, the number of days as an integer for dates, and an interval for timestamps. The distance operator can also be used for nearest neighbor searches using a GiST or an SP-GiST index (see the section called “Indexing”).