The distance operator <->
for set and span types consider the bounding span and returns a the smallest distance between the two values. In the case of time values, the operator returns the number of days or the number of seconds between the two time values. 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 → float
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'; -- 86400 SELECT dateset '{2001-01-01, 2001-01-03, 2001-01-05}' <-> dateset '{2001-01-02, 2001-01-04}'; -- 0