struct_element
SinceVersion 2.0
struct_element
description
Function allows getting a field from a struct.
Syntax
1. struct_element(struct, n/s)
Arguments
1. struct - The input struct column. If null, null will be returned.
2. n - The position of field,starting from 1,only supports constants.
3. s - The name of field,only supports constants.
Returned value
Returns the specified field column, of any type.
notice
Only supported in vectorized engine
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)
9. mysql> select struct_element(named_struct('f1', 1, 'f2', 'a'), 1);
10. +-----------------------------------------------------+
11. | struct_element(named_struct('f1', 1, 'f2', 'a'), 1) |
12. +-----------------------------------------------------+
13. | 1 |
14. +-----------------------------------------------------+
15. 1 row in set (0.02 sec)
17. mysql> select struct_col, struct_element(struct_col, 'f1') from test_struct;
18. +-------------------------------------------------+-------------------------------------+
19. | struct_col | struct_element(`struct_col `, 'f1') |
20. +-------------------------------------------------+-------------------------------------+
21. | {1, 2, 3, 4, 5} | 1 |
22. | {1, 1000, 10000000, 100000000000, 100000000000} | 1 |
23. | {5, 4, 3, 2, 1} | 5 |
24. | NULL | NULL |
25. | {1, NULL, 3, NULL, 5} | 1 |
26. +-------------------------------------------------+-------------------------------------+
27. 9 rows in set (0.01 sec)
keywords
STRUCT, ELEMENT, STRUCT_ELEMENT
