すべてのプロダクト
Search
ドキュメントセンター

ApsaraDB RDS:ST_AsTableFormat

最終更新日:Mar 28, 2026

ST_AsTable で使用するために、トラジェクトリのカラム型定義をテキストとして返します。

構文

text ST_AsTableFormat(trajectory traj);

パラメーター

パラメーター説明
traj検査するトラジェクトリオブジェクトです。

説明

ST_AsTableFormat は、トラジェクトリオブジェクトを検査し、そのカラムレイアウトを記述するテキスト文字列を返します。例:

(t timestamp, x double precision, y double precision, sog real, cog integer, hdg integer, rot integer, status integer, is_satelite smallint, statictime integer)

トラジェクトリの属性はデータセットによって異なるため、ST_AsTable のカラム型をハードコーディングすることはできません。まず ST_AsTableFormat を呼び出して実際のカラム定義を検査し、それを ST_AsTable に渡してトラジェクトリをリレーショナルテーブルに展開します。

トラジェクトリのカラム定義の取得

次の例では、トラジェクトリオブジェクトからカラム型定義を取得します。

SELECT ST_AsTableFormat(
  '{"trajectory":{"version":1,"type":"STPOINT","leafcount":1,
    "start_time":"2010-01-01 11:30:00","end_time":"2010-01-01 11:30:00",
    "spatial":"SRID=4326;POINT(1 1)","timeline":["2010-01-01 11:30:00"],
    "attributes":{"leafcount":1,
      "i1":{"type":"integer","length":1,"nullable":true,"value":[1]},
      "i2":{"type":"integer","length":2,"nullable":true,"value":[1]},
      "i4":{"type":"integer","length":4,"nullable":true,"value":[1]},
      "i8":{"type":"integer","length":8,"nullable":true,"value":[1]},
      "f4":{"type":"float","length":4,"nullable":true,"value":[1]},
      "f8":{"type":"float","length":8,"nullable":true,"value":[1]},
      "string":{"type":"string","length":10,"nullable":true,"value":["fat"]},
      "timestamp":{"type":"timestamp","length":8,"nullable":true,"value":["2010-01-01 11:30:00"]},
      "bool":{"type":"bool","length":1,"nullable":true,"value":["true"]}}}}'::trajectory
);
-- Result:
-- (t timestamp, x double precision, y double precision, i1 integer, i2 smallint,
--  i4 integer, i8 bigint, f4 real, f8 double precision, string text,
--  timestamp timestamp, bool boolean)

出力は、各トラジェクトリ属性を対応する PostgreSQL のカラム型にマッピングします。

属性軌道の入力SQL カラム型
i1integer, 長さ 1integer
i2integer, 長さ 2smallint
i4integer, 長さ 4integer
i8integer, 長さ 8bigint
f4float, 長さ 4real
f8float, 長さ 8double precision
stringstringtext
timestamptimestamptimestamp
boolboolboolean

トラジェクトリのテーブルへの展開

次の例は、ST_AsTableFormat を呼び出してカラム定義を取得し、それを ST_AsTable に渡してトラジェクトリをクエリ可能なテーブルに展開するという、完全な 2 段階のワークフローを示しています。

ステップ 1. カラム定義を取得します。

SELECT ST_AsTableFormat(traj) FROM table_name LIMIT 1;
-- Result:
-- (t timestamp, x double precision, y double precision, sog real, cog integer,
--  hdg integer, rot integer, status integer, is_satelite smallint, statictime integer)

ステップ 2. ST_AsTable で定義を使用してトラジェクトリを展開します。

SELECT f.*
FROM table_name,
     ST_AsTable(traj) AS f(
       t timestamp, x double precision, y double precision,
       sog real, cog integer, hdg integer, rot integer,
       status integer, is_satelite smallint, statictime integer
     );

次のステップ

  • ST_AsTableST_AsTableFormat によって返されたカラム定義を使用して、トラジェクトリをリレーショナルテーブルに変換します。