auto_partition_name

description

Syntax

VARCHAR AUTO_PARTITION_NAME('RANGE', 'VARCHAR unit', DATETIME datetime)

VARCHAR AUTO_PARTITION_NAME('LIST', VARCHAR,...)

Generate datetime partition names by unit following RANGE’s partition name rules

Convert strings to partition names following LIST’s partition name rules

The datetime parameter is a legal date expression.

The unit parameter is the time interval you want, the available values are: [second, minute, hour, day, month, year]. If unit does not match one of these options, a syntax error will be returned.

example

  1. mysql> select auto_partition_name('range', 'years', '123');
  2. ERROR 1105 (HY000): errCode = 2, detailMessage = range auto_partition_name must accept year|month|day|hour|minute|second for 2nd argument
  3. mysql> select auto_partition_name('range', 'year', '2022-12-12 19:20:30');
  4. +---------------------------------------------------------------+
  5. | auto_partition_name('range', 'year', '2022-12-12 19:20:30') |
  6. +---------------------------------------------------------------+
  7. | p20220101000000 |
  8. +---------------------------------------------------------------+
  9. mysql> select auto_partition_name('range', 'month', '2022-12-12 19:20:30');
  10. +---------------------------------------------------------------+
  11. | auto_partition_name('range', 'month', '2022-12-12 19:20:30') |
  12. +---------------------------------------------------------------+
  13. | p20221201000000 |
  14. +---------------------------------------------------------------+
  15. mysql> select auto_partition_name('range', 'day', '2022-12-12 19:20:30');
  16. +---------------------------------------------------------------+
  17. | auto_partition_name('range', 'day', '2022-12-12 19:20:30') |
  18. +---------------------------------------------------------------+
  19. | p20221212000000 |
  20. +---------------------------------------------------------------+
  21. mysql> select auto_partition_name('range', 'hour', '2022-12-12 19:20:30');
  22. +---------------------------------------------------------------+
  23. | auto_partition_name('range', 'hour', '2022-12-12 19:20:30') |
  24. +---------------------------------------------------------------+
  25. | p20221212190000 |
  26. +---------------------------------------------------------------+
  27. mysql> select auto_partition_name('range', 'minute', '2022-12-12 19:20:30');
  28. +---------------------------------------------------------------+
  29. | auto_partition_name('range', 'minute', '2022-12-12 19:20:30') |
  30. +---------------------------------------------------------------+
  31. | p20221212192000 |
  32. +---------------------------------------------------------------+
  33. mysql> select auto_partition_name('range', 'second', '2022-12-12 19:20:30');
  34. +---------------------------------------------------------------+
  35. | auto_partition_name('range', 'second', '2022-12-12 19:20:30') |
  36. +---------------------------------------------------------------+
  37. | p20221212192030 |
  38. +---------------------------------------------------------------+
  39. mysql> select auto_partition_name('list', 'helloworld');
  40. +-------------------------------------------+
  41. | auto_partition_name('list', 'helloworld') |
  42. +-------------------------------------------+
  43. | phelloworld10 |
  44. +-------------------------------------------+
  45. mysql> select auto_partition_name('list', 'hello', 'world');
  46. +-----------------------------------------------+
  47. | auto_partition_name('list', 'hello', 'world') |
  48. +-----------------------------------------------+
  49. | phello5world5 |
  50. +-----------------------------------------------+
  51. mysql> select auto_partition_name('list', "你好");
  52. +------------------------------------+
  53. | auto_partition_name('list', "你好") |
  54. +------------------------------------+
  55. | p4f60597d2 |
  56. +------------------------------------+

keywords

  1. AUTO_PARTITION_NAME,AUTO,PARTITION,NAME