SelectDB Enterprise
参考手册
SQL 函数
标量函数
STRUCT 函数
STRUCT_ELEMENT

STRUCT_ELEMENT

描述

返回 struct 数据列内的某一 field

语法

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

参数

参数说明
<struct>输入的 struct 列,如果是 null,则返回 null
<filed_location>field 的位置,起始位置从 1 开始,仅支持常量
<filed_name>field 的名字,仅支持常量,大小写敏感

返回值

返回指定的 field 列,类型为任意类型

举例

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 |
+-------------------------------------------------+-------------------------------------+
© 2025 北京飞轮数据科技有限公司 京ICP备2022004029号 | Apache、Apache Doris 以及相关开源项目名称均为 Apache 基金会商标