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”).
Return the smallest distance ever
numbers <-> numbers → base
dates <-> dates → integer
times <-> times → interval
{base,spatialset} <-> {base,spatialset} → float
setDistance({geography,geogset},{geography,geogset},spheroid boolean=true) → float
For geographies, the operator computes on the WGS 84 spheroid, and the function setDistance computes on the sphere, faster, if its last argument is false.
SELECT 3 <-> intspan '[6, 8)';
-- 3
SELECT intset '{1, 10}' <-> 5;
-- 0
SELECT floatspan '[1, 3]' <-> floatspan '(5.5, 7]';
-- 2.5
SELECT floatspan '[1, 3]' <-> floatspanset '{(5.5, 7],[8, 9]}';
-- 2.5
SELECT tstzspan '[2001-01-02, 2001-01-06)' <-> timestamptz '2001-01-07';
-- 1 day
SELECT dateset '{2001-01-01, 2001-01-03, 2001-01-05}' <->
dateset '{2001-01-02, 2001-01-04}';
-- 0
SELECT round((geography 'Point(0 0)' <->
geogset '{"Point(0 1)", "Point(0 2)"}')::numeric, 3);
-- 110574.389
SELECT round(setDistance(geography 'Point(0 0)', geogset '{"Point(0 1)", "Point(0 2)"}',
false)::numeric, 3);
-- 111195.080