All Products
Search
Document Center

ApsaraDB RDS:ST_InsertAttr

Last Updated:Apr 01, 2024

This topic describes the ST_InsertAttr function. This function inserts an attribute to a trajectory.

Syntax

trajectory ST_InsertAttr(trajectory traj, anyarray arr, text name, integer loc default -1);

Return value

The new trajectory.

Parameters

Parameter

Description

traj

The original trajectory.

arr

An array that contains the value of the new attribute.

name

The name of the new attribute.

loc

The position at which the new attribute is inserted. Valid values: [-n,n]. A value of n indicates the number of existing attributes.

  • If the value of n is a positive number, the value starts from 0. The value 0 indicates that the new attribute is inserted before the leftmost column, and the value n indicates that the new attribute is inserted after the Nth column counted from left to right.

  • If the value of n is a negative number, the new attribute is inserted from the rightmost column. The value -1 indicates that the new attribute is inserted after the rightmost column, and the value -n indicates that the new attribute is inserted after the leftmost column.

Description

This function inserts an array that contains the new attribute to a trajectory.

Examples

With traj as (select ST_MakeTrajectory('STPOINT'::leaftype,
                                       st_geomfromtext('LINESTRING (114 35, 115 36, 116 37)', 4326),
                                       '[2010-01-01 14:30, 2010-01-01 15:30)'::tsrange,
                                       '{"leafcount":3,"attributes":{"velocity": {"type": "integer", "length": 2,"nullable" : true,"value": [120, 130, 140]}, "accuracy": {"type": "float", "length": 4, "nullable" : false,"value": [120, 130, 140]}, "bearing": {"type": "float", "length": 8, "nullable" : false,"value": [120, 130, 140]}, "acceleration": {"type": "string", "length": 20, "nullable" : true,"value": ["120", "130", "140"]}, "active": {"type": "timestamp", "nullable" : false,"value": ["Fri Jan 01 14:30:00 2010", "Fri Jan 01 15:00:00 2010", "Fri Jan 01 15:30:00 2010"]}}}') as tj)
SELECT ST_InsertAttr(tj, ARRAY[1, 4, 6], 'add', 3) from traj;

Result:

{"trajectory":{"version":1,"type":"STPOINT","leafcount":3,"start_time":"2010-01-01 14:30:00","end_time":"2010-01-01 15:30:00","spatial":"SRID=4326;LINESTRING(114 35,115 36,116 37)","timeline":["2010-01-01 14:30:00","2010-01-01 15:00:00","2010-01-01 15:30:00"],"attributes":{"leafcount":3,"velocity":{"type":"integer","length":2,"nullable":true,"value":[120,130,140]},"accuracy":{"type":"float","length":4,"nullable":false,"value":[120.0,130.0,140.0]},"bearing":{"type":"float","length":8,"nullable":false,"value":[120.0,130.0,140.0]},"add":{"type":"integer","length":4,"nullable":true,"value":[1,4,6]},"acceleration":{"type":"string","length":20,"nullable":true,"value":["120","130","140"]},"active":{"type":"timestamp","length":8,"nullable":false,"value":["2010-01-01 14:30:00","2010-01-01 15:00:00","2010-01-01 15:30:00"]}}}}