struct_element

SinceVersion 2.0

struct_element

description

返回struct数据列内的某一field

Syntax

  1. struct_element(struct, n/s)

Arguments

  1. struct - 输入的struct列,如果是null,则返回null
  2. n - field的位置,起始位置从1开始,仅支持常量
  3. s - field的名字,仅支持常量

Returned value

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

notice

只支持在向量化引擎中使用。

example

  1. mysql> select struct_element(named_struct('f1', 1, 'f2', 'a'), 'f2');
  2. +--------------------------------------------------------+
  3. | struct_element(named_struct('f1', 1, 'f2', 'a'), 'f2') |
  4. +--------------------------------------------------------+
  5. | a |
  6. +--------------------------------------------------------+
  7. 1 row in set (0.03 sec)
  8. mysql> select struct_element(named_struct('f1', 1, 'f2', 'a'), 1);
  9. +-----------------------------------------------------+
  10. | struct_element(named_struct('f1', 1, 'f2', 'a'), 1) |
  11. +-----------------------------------------------------+
  12. | 1 |
  13. +-----------------------------------------------------+
  14. 1 row in set (0.02 sec)
  15. mysql> select struct_col, struct_element(struct_col, 'f1') from test_struct;
  16. +-------------------------------------------------+-------------------------------------+
  17. | struct_col | struct_element(`struct_col `, 'f1') |
  18. +-------------------------------------------------+-------------------------------------+
  19. | {1, 2, 3, 4, 5} | 1 |
  20. | {1, 1000, 10000000, 100000000000, 100000000000} | 1 |
  21. | {5, 4, 3, 2, 1} | 5 |
  22. | NULL | NULL |
  23. | {1, NULL, 3, NULL, 5} | 1 |
  24. +-------------------------------------------------+-------------------------------------+
  25. 9 rows in set (0.01 sec)

keywords

STRUCT, ELEMENT, STRUCT_ELEMENT