The distance operator <-> for set and span types consider the bounding span and returns the smallest distance between the two values. 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 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