ST_attrDefinition

更新时间:
复制 MD 格式

Returns the definitions of all attributes in a trajectory object as a JSON string.

Syntax

text ST_attrDefinition(trajectory traj)

Parameters

ParameterTypeDescription
trajtrajectoryThe trajectory object to inspect.

Return value

Returns a text value containing a JSON object with the following structure:

{
  "size": <integer>,
  "<attribute_name>": {
    "type": "<data_type>",
    "length": <integer>,
    "nullable": <boolean>
  },
  ...
}
FieldDescription
sizeThe number of attributes in the trajectory object.
<attribute_name>The name of an attribute (for example, velocity, speed). The JSON object contains one entry per attribute.
typeThe data type of the attribute. Valid values: integer, float, string, timestamp, bool.
lengthThe storage length of the attribute in bytes.
nullableWhether the attribute accepts null values.

Example

The following example creates a trajectory object with five attributes — velocity, speed, angle, tngel2, and bearing — and then calls ST_attrDefinition to retrieve their definitions.

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_attrDefinition(a) FROM traj;

Output:

{
  "size": 5,
  "velocity":  {"type": "integer",   "length": 4, "nullable": true},
  "speed":     {"type": "float",     "length": 8, "nullable": true},
  "angle":     {"type": "string",    "length": 64,"nullable": true},
  "tngel2":    {"type": "timestamp", "length": 8, "nullable": true},
  "bearing":   {"type": "bool",      "length": 1, "nullable": true}
}

The output contains "size": 5, confirming five attributes. Each attribute entry shows its type, storage length, and nullability. Attribute values are not included; to retrieve them, use the corresponding accessor functions.