Tous les produits
Search
Centre de documentation

ApsaraDB RDS:ST_InsertAttr

Dernière mise à jour :Oct 10, 2026

Insère un nouvel attribut dans une trajectoire à une position donnée.

Syntaxe

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

Valeur de retour

La trajectoire modifiée, renvoyée sous forme de valeur trajectory, avec le nouvel attribut inséré à la position indiquée.

Paramètres

Paramètre Type Par défaut Description
traj trajectory — La trajectoire d'origine.
arr anyarray — Tableau de valeurs pour le nouvel attribut.
name text — Nom du nouvel attribut.
loc integer -1 Position d'insertion du nouvel attribut. Valeurs acceptées : [-n, n], où n correspond au nombre d'attributs existants. Si ce paramètre est omis, l'attribut est ajouté après le dernier attribut (équivalent à loc = -1).

Notes d'utilisation

  • **Index positif (de 0 à n)** : Le comptage se fait depuis la gauche. 0 insère avant le premier attribut ; n insère après le n-ième attribut en partant de la gauche.

  • **Index négatif (de -1 à -n)** : Le comptage se fait depuis la droite. -1 ajoute après le dernier attribut ; -n insère après l'attribut le plus à gauche.

Exemples

Ajouter un attribut à la fin (comportement par défaut)

Omettre loc revient à utiliser loc = -1, ce qui ajoute le nouvel attribut après tous les attributs existants.

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') from traj;

Insérer un attribut après le troisième attribut en partant de la gauche

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;

Résultat :

{"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"]}}}}

Insérer un attribut avant le premier attribut

Utilisez loc = 0 pour placer le nouvel attribut avant tous les attributs existants.

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', 0) from traj;

Étapes suivantes

  • ST_AppendAttr : Ajoute un attribut à la fin d'une trajectoire.

  • ST_SetAttr : Met à jour les valeurs d'un attribut de trajectoire existant.

  • ST_DeleteAttr : Supprime un attribut d'une trajectoire.