メインコンテンツまでスキップ
バージョン: 2.1

STRUCT_ELEMENT

説明

構造体のデータ列内の特定のフィールドを返します。

構文

STRUCT_ELEMENT( <struct>, '<filed_location>/<filed_name>')

パラメータ

Parameterデスクリプション
<struct>入力のstruct列がnullの場合、nullを返す
<filed_location>フィールドの位置は1から始まり、定数のみがサポートされる
<filed_name>フィールド名は定数である必要があり、大文字小文字を区別する

Return Value

指定されたフィールド列を返し、型は任意の型となる

Example

select struct_element(named_struct('f1', 1, 'f2', 'a'), 'f2'),struct_element(named_struct('f1', 1, 'f2', 'a'), 1);
+--------------------------------------------------------+-----------------------------------------------------+
| struct_element(named_struct('f1', 1, 'f2', 'a'), 'f2') | struct_element(named_struct('f1', 1, 'f2', 'a'), 1) |
+--------------------------------------------------------+-----------------------------------------------------+
| a | 1 |
+--------------------------------------------------------+-----------------------------------------------------+
select struct_col, struct_element(struct_col, 'f1') from test_struct;
+-------------------------------------------------+-------------------------------------+
| struct_col | struct_element(`struct_col `, 'f1') |
+-------------------------------------------------+-------------------------------------+
| {1, 2, 3, 4, 5} | 1 |
| {1, 1000, 10000000, 100000000000, 100000000000} | 1 |
| {5, 4, 3, 2, 1} | 5 |
| NULL | NULL |
| {1, NULL, 3, NULL, 5} | 1 |
+-------------------------------------------------+-------------------------------------+