Join 2 tables by closest time, PostgreSQL 9.6
Using btree_gist and &lt;-&gt;

You really want &lt;-&gt; which will actually work on GiST indexes through the internal tstz_dist. This works because you don't really care about the interval. First you need to add the extension,

CREATE EXTENSION btree_gist;


then

SELECT DISTINCT ON (time_1) time_1, time_2
FROM tbl1
CROSS JOIN tbl2
ORDER BY time_1, time_1 &lt;-&gt; time_2;


If there are too many rows to do a cross-join, you may have better luck with the lateral solution.

SELECT time_1, time_2
FROM tbl1
CROSS JOIN LATERAL (
  SELECT time_2
  FROM tbl2
  ORDER BY time_1&lt;-&gt;time_2
  LIMIT 1
) AS tbl2;


Would be interested in seeing a report back on the benchmarks. =) Especially if you have a GIST index on time_1 and time_2.