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 カラム型 |
|---|---|---|
i1 | integer, 長さ 1 | integer |
i2 | integer, 長さ 2 | smallint |
i4 | integer, 長さ 4 | integer |
i8 | integer, 長さ 8 | bigint |
f4 | float, 長さ 4 | real |
f8 | float, 長さ 8 | double precision |
string | string | text |
timestamp | timestamp | timestamp |
bool | bool | boolean |
トラジェクトリのテーブルへの展開
次の例は、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_AsTable —
ST_AsTableFormatによって返されたカラム定義を使用して、トラジェクトリをリレーショナルテーブルに変換します。