All Products
Search
Document Center

ApsaraDB RDS:ST_difference

Last Updated:Mar 28, 2026

Returns a trajectory object representing the part of a trajectory, within a specified time range, that does not intersect with a geometry object.

Syntax

trajectory ST_difference(trajectory traj, tsrange range, geometry g);
trajectory ST_difference(trajectory traj, timestamp t1, timestamp t2, geometry g);

Parameters

ParameterTypeDescription
trajtrajectoryThe trajectory object.
rangetsrangeThe time range within which to compute the difference.
t1timestampThe start time of the time range.
t2timestampThe end time of the time range.
ggeometryThe specified geometry object.

Example

The following example uses the timestamp variant to return the segments of a trajectory between 13:00 and 14:00 that fall outside the specified line string.

SELECT ST_difference(traj, '2010-1-1 13:00:00', '2010-1-1 14:00:00', 'LINESTRING(0 0, 5 5, 9 9)'::geometry)
FROM traj_table;
-- Returns the trajectory segments within the time window that do not intersect LINESTRING(0 0, 5 5, 9 9)