struct()

SinceVersion 2.0.0

struct()

description

Syntax

STRUCT<T1, T2, T3, ...> struct(T1, T2, T3, ...)

construct an struct with variadic elements and return it, Tn could be column or literal

notice

Only supported in vectorized engine

example

  1. mysql> select struct(1, 'a', "abc");
  2. +-----------------------+
  3. | struct(1, 'a', 'abc') |
  4. +-----------------------+
  5. | {1, 'a', 'abc'} |
  6. +-----------------------+
  7. 1 row in set (0.03 sec)
  8. mysql> select struct(null, 1, null);
  9. +-----------------------+
  10. | struct(NULL, 1, NULL) |
  11. +-----------------------+
  12. | {NULL, 1, NULL} |
  13. +-----------------------+
  14. 1 row in set (0.02 sec)
  15. mysql> select struct(cast('2023-03-16' as datetime));
  16. +----------------------------------------+
  17. | struct(CAST('2023-03-16' AS DATETIME)) |
  18. +----------------------------------------+
  19. | {2023-03-16 00:00:00} |
  20. +----------------------------------------+
  21. 1 row in set (0.01 sec)
  22. mysql> select struct(k1, k2, null) from test_tb;
  23. +--------------------------+
  24. | struct(`k1`, `k2`, NULL) |
  25. +--------------------------+
  26. | {1, 'a', NULL} |
  27. +--------------------------+
  28. 1 row in set (0.04 sec)

keywords

STRUCT,CONSTRUCTOR