ST_attrLength
Updated at:
Copy as MD
Returns the defined byte length of a trajectory attribute field.
Syntax
integer ST_attrLength(trajectory traj, integer index);
integer ST_attrLength(trajectory traj, text name);Parameters
| Parameter | Type | Description |
|---|---|---|
traj | trajectory | The trajectory object. |
index | integer | The zero-based index of the attribute field. |
name | text | The name of the attribute field. |
Examples
Query the length of the first attribute field (index 0) in 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"],"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_attrLength(a, 0) FROM traj;Output:
st_attrlength
---------------
4
(1 row)Query the same field by name:
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_attrLength(a, 'velocity') FROM traj;Output:
st_attrlength
---------------
4
(1 row)Both calls return 4, which is the defined byte length of the velocity attribute (type integer, 4 bytes).
Is this page helpful?