named_struct

SinceVersion 2.0.0

named_struct

description

Syntax

STRUCT<T1, T2, T3, ...> named_struct({VARCHAR, T1}, {VARCHAR, T2}, ...)

Construct a struct with the given field names and values.

The number of parameters must be non zero and even. With odd digits being the name of the field and could be string literal, with even digits being the value of the field and could be column or literal.

notice

Only supported in vectorized engine

example

  1. mysql> select named_struct('f1', 1, 'f2', 'a', 'f3', "abc");
  2. +-----------------------------------------------+
  3. | named_struct('f1', 1, 'f2', 'a', 'f3', 'abc') |
  4. +-----------------------------------------------+
  5. | {1, 'a', 'abc'} |
  6. +-----------------------------------------------+
  7. 1 row in set (0.01 sec)
  8. mysql> select named_struct('a', null, 'b', "v");
  9. +-----------------------------------+
  10. | named_struct('a', NULL, 'b', 'v') |
  11. +-----------------------------------+
  12. | {NULL, 'v'} |
  13. +-----------------------------------+
  14. 1 row in set (0.01 sec)
  15. mysql> select named_struct('f1', k1, 'f2', k2, 'f3', null) from test_tb;
  16. +--------------------------------------------------+
  17. | named_struct('f1', `k1`, 'f2', `k2`, 'f3', NULL) |
  18. +--------------------------------------------------+
  19. | {1, 'a', NULL} |
  20. +--------------------------------------------------+
  21. 1 row in set (0.02 sec)

keywords

NAMED, STRUCT, NAMED_STRUCT