All Products
Search
Document Center

PolarDB:ST_durationWithin

Last Updated:Mar 28, 2026

Returns true if two trajectory objects intersect at the same spatial point within a specified time range and the difference between their intersection timestamps falls within the reference interval.

Syntax

boolean ST_durationWithin(trajectory traj1, trajectory traj2, tsrange range, interval i);
boolean ST_durationWithin(trajectory traj1, trajectory traj2, timestamp t1, timestamp t2, interval i);

Parameters

ParameterDescription
traj1, traj2The trajectory objects to compare.
rangeThe time range to search for intersections, specified as a tsrange value.
t1The start of the time range.
t2The end of the time range.
iThe reference interval. The function returns true if the difference between the intersection timestamps of the two trajectories is within this interval.

Usage notes

  • If the two trajectories intersect at the same spatial point more than once within the specified time range, the function returns true as long as any one of those intersections has a timestamp difference within the reference interval.

  • The two overloads are equivalent. Use tsrange when the time range is already stored as a range type; use t1 and t2 when you have discrete timestamp values.

Example

Check whether two trajectories intersect at the same spatial point between 13:00 and 14:00 on January 1, 2010, and whether their timestamp difference at any such intersection is within 30 seconds:

SELECT ST_durationWithin(
  (SELECT traj FROM traj_table WHERE id = 1),
  (SELECT traj FROM traj_table WHERE id = 2),
  '2010-01-01 13:00:00',
  '2010-01-01 14:00:00',
  INTERVAL '30s'
);