All Products
Search
Document Center

PolarDB:ST_difference

Last Updated:Mar 28, 2026

Returns a new trajectory object that indicates the difference between a trajectory object within the specified time range and the specified geometry object.

Syntax

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

Two overloads are available: one accepts a tsrange value, the other accepts explicit start and end timestamps.

Parameters

ParameterTypeDescription
trajtrajectoryThe source trajectory to evaluate.
rangetsrangeThe time range to evaluate.
t1timestampThe start of the time range to evaluate.
t2timestampThe end of the time range to evaluate.
ggeometryThe geometry object to subtract from the trajectory.

Example

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;