ST_attrLength

更新时间:
复制 MD 格式

Returns the defined length of a trajectory attribute field.

Syntax

integer ST_attrLength(trajectory traj, integer index);
integer ST_attrLength(trajectory traj, text name);

Parameters

ParameterDescription
trajThe trajectory object.
indexThe attribute index.
nameThe name of the attribute field.

Examples

The following examples query the velocity attribute field (type integer, length 4) of a sample trajectory using an index and a name.

Query by index

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;  -- index 0 is "velocity", an integer field (4 bytes)

Output:

 st_attrlength
---------------
             4
(1 row)

Query 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;  -- "velocity" is an integer field (4 bytes)

Output:

 st_attrlength
---------------
             4
(1 row)