ST_attrType
Returns the data type of an attribute field in a trajectory object.
Syntax
text ST_attrType(trajectory traj, integer index);
text ST_attrType(trajectory traj, text name);Parameters
| Parameter | Description |
|---|---|
traj | The trajectory object. |
index | The attribute index. |
name | The name of the attribute field. |
Description
ST_attrType returns a string identifying the data type of the specified attribute field. The possible return values are: integer, float, string, timestamp, and bool.
Use the index-based overload when iterating over all fields; use the name-based overload when the field name is known.
Examples
Both examples query the same trajectory object — a two-point STPOINT trajectory with five typed attribute fields: velocity (integer), speed (float), angle (string), tngel2 (timestamp), and bearing (bool).
Query by index
Pass 0 to get the data type of the first attribute field (velocity).
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"],"attributes":{"leafcount":2,"velocity":{"type":"integer","length":4,"nullable":true,"value":[1,null]},"speed":{"type":"float","length":8,"nullable":true,"value":[null,1.0]},"angle":{"type":"string","length":64,"nullable":true,"value":["test",null]}, "tngel2":{"type":"timestamp","length":8,"nullable":true,"value":["2010-01-01 12:30:00",null]},"bearing":{"type":"bool","length":1,"nullable":true,"value":[null,true]}}}}'::trajectory a)
Select st_attrType(a, 0) from traj;Output:
st_attrtype
-------------
integer
(1 row)Query by name
Pass the field name 'velocity' to get its data type directly.
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"],"attributes":{"leafcount":2,"velocity":{"type":"integer","length":4,"nullable":true,"value":[1,null]},"speed":{"type":"float","length":8,"nullable":true,"value":[null,1.0]},"angle":{"type":"string","length":64,"nullable":true,"value":["test",null]}, "tngel2":{"type":"timestamp","length":8,"nullable":true,"value":["2010-01-01 12:30:00",null]},"bearing":{"type":"bool","length":1,"nullable":true,"value":[null,true]}}}}'::trajectory a)
Select st_attrType(a, 'velocity') from traj;Output:
st_attrtype
-------------
integer
(1 row)What's next
ST_attrCount — get the total number of attribute fields in a trajectory
ST_attrName — get the name of an attribute field by index
ST_attrValue — get the value of an attribute field