All Products
Search
Document Center

PolarDB:ST_AsTableFormat

Last Updated:Mar 28, 2026

Returns the column definition string for a trajectory object, which you pass directly to ST_AsTable to expand the trajectory into a relational table.

Syntax

text ST_AsTableFormat(trajectory traj);

Parameters

ParameterDescription
trajThe trajectory object to inspect.

Description

ST_AsTableFormat reads the attribute schema of a trajectory and returns it as a text string in PostgreSQL column-definition format. The returned string lists each column name and its SQL data type, separated by commas, enclosed in parentheses — for example:

(t timestamp, x double precision, y double precision, i1 integer, ...)

The column list always starts with t (the timestamp column) and x, y (the spatial coordinates). Attribute columns follow in the order they appear in the trajectory definition. Trajectory attribute types map to SQL column types as follows:

Trajectory attribute typeLengthSQL column type
integer1 byteinteger
integer2 bytessmallint
integer4 bytesinteger
integer8 bytesbigint
float4 bytesreal
float8 bytesdouble precision
stringanytext
timestamp8 bytestimestamp
bool1 byteboolean

Usage notes

ST_AsTableFormat is a helper function for ST_AsTable. The typical workflow is:

  1. Call ST_AsTableFormat on a sample trajectory to get the column definition string.

  2. Copy the output and use it as the column list in ST_AsTable to expand trajectories into rows.

The two functions must be used together — ST_AsTableFormat alone does not expand any data.

Examples

Expand a trajectory table using ST_AsTableFormat output

First, get the column definition string for a trajectory in your table:

SELECT ST_AsTableFormat(traj) FROM table_name LIMIT 1;

Copy the output, then use it as the column specification in ST_AsTable:

SELECT f.*
FROM table_name,
     ST_AsTable(traj) AS f(t timestamp, x double precision, y double precision, sog real, cog integer, hdg integer, rot integer, status integer, is_satelite smallint, statictime integer);

Get the column definition for an inline trajectory

The following example calls ST_AsTableFormat on a trajectory value constructed inline:

SELECT ST_AsTableFormat(
  '{"trajectory":{"version":1,"type":"STPOINT","leafcount":1,"start_time":"2010-01-01 11:30:00","end_time":"2010-01-01 11:30:00","spatial":"SRID=4326;POINT(1 1)","timeline":["2010-01-01 11:30:00"],"attributes":{"leafcount":1,"i1":{"type":"integer","length":1,"nullable":true,"value":[1]},"i2":{"type":"integer","length":2,"nullable":true,"value":[1]},"i4":{"type":"integer","length":4,"nullable":true,"value":[1]},"i8":{"type":"integer","length":8,"nullable":true,"value":[1]},"f4":{"type":"float","length":4,"nullable":true,"value":[1]},"f8":{"type":"float","length":8,"nullable":true,"value":[1]},"string":{"type":"string","length":10,"nullable":true,"value":["fat"]},"timestamp":{"type":"timestamp","length":8,"nullable":true,"value":["2010-01-01 11:30:00"]},"bool":{"type":"bool","length":1,"nullable":true,"value":["true"]}}}}'::trajectory
);

Output:

(t timestamp, x double precision, y double precision, i1 integer, i2 smallint, i4 integer, i8 bigint, f4 real, f8 double precision, string text, timestamp timestamp, bool boolean)