All Products
Search
Document Center

PolarDB:ST_AsTable

Last Updated:Mar 28, 2026

Converts a trajectory object into a set of rows, one row per trajectory point.

Syntax

trajectory ST_AsTable(trajectory traj)

Parameters

ParameterDescription
trajThe trajectory to convert.

Description

ST_AsTable is a set-returning function that expands a trajectory object into a relational table. Each row in the output represents a single trajectory point. The output schema matches the format defined by Syntax 5 in ST_makeTrajectory.

Call ST_AsTable in two ways:

  • In a SELECT clause — returns a composite tuple per row

  • In a FROM clause with column aliases — expands the result into named columns you can query directly

Examples

Return tuples from a trajectory

WITH traj AS (
    SELECT '{"trajectory":{"version":1,"type":"STPOINT","leafcount":2,"start_time":"2010-01-01 11:30:00","end_time":"2010-01-01 12:30:00","spatial":"SRID=4326;LINESTRING(1 1,3 5)","timeline":["2010-01-01 11:30:00","2010-01-01 12:30:00"]}}'::trajectory a
)
SELECT ST_AsTable(a) FROM traj;

Output:

         st_astable
-----------------------------
 ("2010-01-01 11:30:00",1,1)
 ("2010-01-01 12:30:00",3,5)
(2 rows)

Expand a trajectory into named columns

Use ST_AsTable in the FROM clause and assign column aliases to query individual fields directly.

SELECT *
FROM ST_AsTable(
    '{"trajectory":{"version":1,"type":"STPOINT","leafcount":2,"start_time":"2010-01-01 11:30:00","end_time":"2010-01-01 12:30:00","spatial":"SRID=4326;LINESTRING(1 1,3 5)","timeline":["2010-01-01 11:30:00","2010-01-01 12:30:00"]}}'::trajectory
) AS f(t timestamp, x double precision, y double precision);

Output:

          t          | x | y
---------------------+---+---
 2010-01-01 11:30:00 | 1 | 1
 2010-01-01 12:30:00 | 3 | 5
(2 rows)