SelectDB Cloud
SQL 手册
SQL 函数
字符串函数
auto_partition_name

:::tip 提示 该功能自 Apache Doris 3.0.2 版本起支持 :::

Description

Syntax

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

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

遵循 RANGE 的分区名规则将 datetime 按照 unit 生成分区名

遵循 LIST 的分区名规则将字符串转换为分区名

datetime 参数是合法的日期表达式。

unit 参数是您希望的时间间隔,可选的值如下:[second,minute,hour,day,month,year]。 如果 unit 不符合上述可选值,结果将返回语法错误。

Example

mysql> select auto_partition_name('range', 'years', '123');
ERROR 1105 (HY000): errCode = 2, detailMessage = range auto_partition_name must accept year|month|day|hour|minute|second for 2nd argument
 
mysql> select auto_partition_name('range', 'year', '2022-12-12 19:20:30');
+---------------------------------------------------------------+
| auto_partition_name('range', 'year', '2022-12-12 19:20:30')   |
+---------------------------------------------------------------+
| p20220101000000                                               |
+---------------------------------------------------------------+
 
mysql> select auto_partition_name('range', 'month', '2022-12-12 19:20:30');
+---------------------------------------------------------------+
| auto_partition_name('range', 'month', '2022-12-12 19:20:30')  |
+---------------------------------------------------------------+
| p20221201000000                                               |
+---------------------------------------------------------------+
 
mysql> select auto_partition_name('range', 'day', '2022-12-12 19:20:30');
+---------------------------------------------------------------+
| auto_partition_name('range', 'day', '2022-12-12 19:20:30')    |
+---------------------------------------------------------------+
| p20221212000000                                               |
+---------------------------------------------------------------+
 
mysql> select auto_partition_name('range', 'hour', '2022-12-12 19:20:30');
+---------------------------------------------------------------+
| auto_partition_name('range', 'hour', '2022-12-12 19:20:30')   |
+---------------------------------------------------------------+
| p20221212190000                                               |
+---------------------------------------------------------------+
 
mysql> select auto_partition_name('range', 'minute', '2022-12-12 19:20:30');
+---------------------------------------------------------------+
| auto_partition_name('range', 'minute', '2022-12-12 19:20:30') |
+---------------------------------------------------------------+
| p20221212192000                                               |
+---------------------------------------------------------------+
 
mysql> select auto_partition_name('range', 'second', '2022-12-12 19:20:30');
+---------------------------------------------------------------+
| auto_partition_name('range', 'second', '2022-12-12 19:20:30') |
+---------------------------------------------------------------+
| p20221212192030                                               |
+---------------------------------------------------------------+
 
mysql> select auto_partition_name('list', 'helloworld');
+-------------------------------------------+
| auto_partition_name('list', 'helloworld') |
+-------------------------------------------+
| phelloworld10                             |
+-------------------------------------------+
 
mysql> select auto_partition_name('list', 'hello', 'world');
+-----------------------------------------------+
| auto_partition_name('list', 'hello', 'world') |
+-----------------------------------------------+
| phello5world5                                 |
+-----------------------------------------------+
 
mysql> select auto_partition_name('list', "你好");
+------------------------------------+
| auto_partition_name('list', "你好") |
+------------------------------------+
| p4f60597d2                         |
+------------------------------------+

Keywords

AUTO_PARTITION_NAME,AUTO,PARTITION,NAME
© 2023 北京飞轮数据科技有限公司 京ICP备2022004029号 | Apache、Apache Doris 以及相关开源项目名称均为 Apache 基金会商标