diff --git "a/Data_governance/\344\273\243\347\240\201/\344\273\243\347\240\201PR\350\257\264\346\230\216.docx" "b/Data_governance/\344\273\243\347\240\201/\344\273\243\347\240\201PR\350\257\264\346\230\216.docx" new file mode 100644 index 0000000000000000000000000000000000000000..4b3f2797f21800b5f35184670ed64db716e1984d Binary files /dev/null and "b/Data_governance/\344\273\243\347\240\201/\344\273\243\347\240\201PR\350\257\264\346\230\216.docx" differ diff --git "a/Data_governance/\345\207\275\346\225\260\347\211\271\346\200\247\350\256\276\350\256\241\350\257\264\346\230\216\344\271\246/openGauss\345\205\274\345\256\271\346\227\245\346\234\237\345\244\204\347\220\206\345\207\275\346\225\260\347\211\271\346\200\247\350\256\276\350\256\241\350\257\264\346\230\216\344\271\246.pdf" "b/Data_governance/\345\207\275\346\225\260\347\211\271\346\200\247\350\256\276\350\256\241\350\257\264\346\230\216\344\271\246/openGauss\345\205\274\345\256\271\346\227\245\346\234\237\345\244\204\347\220\206\345\207\275\346\225\260\347\211\271\346\200\247\350\256\276\350\256\241\350\257\264\346\230\216\344\271\246.pdf" new file mode 100644 index 0000000000000000000000000000000000000000..986901169cd8a3a023a38b94627f8afe0176c8b0 Binary files /dev/null and "b/Data_governance/\345\207\275\346\225\260\347\211\271\346\200\247\350\256\276\350\256\241\350\257\264\346\230\216\344\271\246/openGauss\345\205\274\345\256\271\346\227\245\346\234\237\345\244\204\347\220\206\345\207\275\346\225\260\347\211\271\346\200\247\350\256\276\350\256\241\350\257\264\346\230\216\344\271\246.pdf" differ diff --git "a/Data_governance/\346\265\213\350\257\225\347\233\270\345\205\263/\346\265\213\350\257\225\346\226\207\346\241\243/openGauss\345\205\274\345\256\271MySQL\346\227\245\346\234\237\345\244\204\347\220\206\345\207\275\346\225\260\346\265\213\350\257\225\346\212\245\345\221\212.md" "b/Data_governance/\346\265\213\350\257\225\347\233\270\345\205\263/\346\265\213\350\257\225\346\226\207\346\241\243/openGauss\345\205\274\345\256\271MySQL\346\227\245\346\234\237\345\244\204\347\220\206\345\207\275\346\225\260\346\265\213\350\257\225\346\212\245\345\221\212.md" new file mode 100644 index 0000000000000000000000000000000000000000..087207bc11787243c77ab4fa50bc329c616fbb29 --- /dev/null +++ "b/Data_governance/\346\265\213\350\257\225\347\233\270\345\205\263/\346\265\213\350\257\225\346\226\207\346\241\243/openGauss\345\205\274\345\256\271MySQL\346\227\245\346\234\237\345\244\204\347\220\206\345\207\275\346\225\260\346\265\213\350\257\225\346\212\245\345\221\212.md" @@ -0,0 +1,208 @@ +![avatar](../../images/openGauss.png) + +版权所有 © 2022 openGauss社区 + 您对“本文档”的复制、使用、修改及分发受知识共享(Creative Commons)署名—相同方式共享4.0国际公共许可协议(以下简称“CC BY-SA 4.0”)的约束。为了方便用户理解,您可以通过访问https://creativecommons.org/licenses/by-sa/4.0/ 了解CC BY-SA 4.0的概要 (但不是替代)。CC BY-SA 4.0的完整协议内容您可以访问如下网址获取:https://creativecommons.org/licenses/by-sa/4.0/legalcode。 + +修订记录 + +| 日期 | 修订 版本 | 修改描述 | 作者 | +| ---------- | ----------- | ------------------------ | ------------ | +| 2022-11-14 | 1.0 | 测试报告初稿完成 | 刘禹锡,郑清林,王阿涛 | +| 2023-1-1 | 2.0 | 测试报告第二版完成 | 刘禹锡,郑清林,王阿涛 | +| 2023-5-14 | 3.0 | 测试报告第三版完成 | 刘禹锡,郑清林,王阿涛 | + +关键词:dolphin插件,日期处理函数,兼容B库,MySQL,openGauss + +摘要:本文档主要介绍openGauss在兼容B库且有dolphin插件的情形下,实现兼容MySQL日期处理函数的功能特性测试。兼容的函数分为四部分,主要测试了正常值,边界值,特异值,非法或无效值,函数结果插表,并将结果与MySQL侧做对比。 + +# 1 特性概述 + +openGauss在兼容B库情形下,安装dolphin插件,可以实现对MySQL的 + +CURDATE() +CURRENT_TIME, +CURRENT_TIME(n), +CURTIME(), +CURRENT_TIMESTAMP, +CURRENT_TIMESTAMP(n), +CURRENT_TIMESTAMP(), +LOCALTIME, +LOCALTIME(), +LOCALTIME(n), +LOCALTIMESTAMP, +LOCALTIMESTAMP(), +LOCALTIMESTAMP(n), +NOW(n), +SYSDATE(n), +DATE(expr), +DAY(date), +DAYNAME(date), +LAST_DAY(date), +MONTH(date), +MONTHNAME(date), +TIME_TO_SEC(time), +WEEK(date[,mode]), +YEARWEEK(date), +YEARWEEK(date,mode), +ADDDATE(date,INTERVAL expr unit), +ADDDATE(expr,days), +DATE_ADD(date,INTERVAL expr unit), +DATE_SUB(date,INTERVAL expr unit), +ADDTIME(expr1,expr2), +CONVERT_TZ(dt,from_tz,to_tz), +DATEDIFF(expr1,expr2), +FROM_DAYS(N), +DATE_FORMAT(date,format), +EXTRACT(unit FROM date), +FROM_UNIXTIME(unix_timestamp[,format]), +GET_FORMAT({DATE|TIME|DATETIME}, {'EUR'|'USA'|'JIS'|'ISO'|'INTERNAL'}), +STR_TO_DATE(str, format), +TIMESTAMPDIFF(unit,datetime_expr1,datetime_expr2), +共39个日期处理函数的兼容,其函数功能及执行结果与MySQL侧一致。 + +# 2 特性测试信息 + +本节描述被测对象的版本信息和测试的时间及测试轮次,包括依赖的硬件。 + +| 版本名称 | 测试起始时间 | 测试结束时间 | +| ------------------------------ | ------------ | ------------ | +| MySQL 5.7 | 2023-5-12 | 2023-5-14 | +| openGauss 3.1.0 build 5d56e686 | 2023-5-12 | 2023-5-14 | +| dolphin xx | 2023-5-12 | 2023-5-14 | + +描述特性测试的环境信息 + +| 环境信息 | 配置信息 | 备注 | +| -------- | ------------------------------------------------------------ | ---- | +| 虚拟机 | MySQL侧:
CPU:Intel(R) Core(TM) i7-12700H 2.30 GHz
内存:12GB
硬盘:70G
OS:CentOS Linux release 7.6 (Core) | | +| 服务器 |openGauss侧:
CPU:kunpeng920-5220 * 2
内存:192GB
硬盘:7.28TB
OS:华为 openEuler 20.03LTS| | + +# 3 测试结论概述 + +## 3.1 测试整体结论 + +openGauss兼容MySQL日期处理函数共计执行用例1244条,主要覆盖了特性功能测试。特性功能测试覆盖有效及无效的入参情形、sql_mode严格模式和非严格模式下的执行、插表情形与MySQL执行结果进行比对。累计发现问题3个,已经过Sig专家确认。 + +1. 日期底层值运算问题(已经过Sig专家确认) + + openGauss日期大于'0000-2-28'时,日期底层值中会包含'0000-2-29',从而如'0000-3-1' - ’0000-2-28‘的日期减法结果比MySQL多一天。 + +2. 日期小于'0001-01-01 00:00:00'时OpenGauss小数秒正常进位。(已经过Sig专家确认) + +3. 函数不支持含零日期(月份或者天数为零)作为入参。(已经过Sig专家确认) + +| 测试活动 | 活动评价 | +| -------- | ------------------------------------------------------------ | +| 功能测试 | 编译库、编译插件,执行结果符合预期,通过 | +| 功能测试 | 有效及无效入参测试,通过 | +| 功能测试 | 特异值输出结果测试,通过 | +| 功能测试 | 日期类型输入多样性输出结果测试,通过 | +| 功能测试 | 在常用sql语句、插表测试的输出结果测试,通过 | +| 功能测试 | 严格模式与非严格模式下对sql语句输出结果测试,通过 | + + +## 3.2 约束说明 + +1. MySQL使用5.7版本 + +2. openGauss需使用兼容B库且有dolphin插件 + +3. openGauss需要用GUC参数dolphin.b_db_timestamp = 0,来控制使用 + CURDATE(), + CURRENT_TIME, + CURRENT_TIME(n), + CURTIME(), + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP(n), + CURRENT_TIMESTAMP(), + LOCALTIME, + LOCALTIME(), + LOCALTIME(n), + LOCALTIMESTAMP, + LOCALTIMESTAMP(), + LOCALTIMESTAMP(n), + NOW(n)共14个函数。 + + 在MySQL侧对应参数名为timestamp。 + +4. dayname函数和monthname函数受GUC参数dolphin.lc_time_names影响,控制其返回内容所在的语言集。 + +5. openGauss需要用GUC参数set dolphin.b_compatibility_mode = true,来控制使用last_day(),timestampdiff(),extract()共3个函数。 + +6. week函数受GUC参数dolphin.default_week_format的影响,改变其mode默认的参数。 + +7. 在openGauss中设置严格或非严格模式对其输出结果会有所不同 + +## 3.3 遗留问题分析 + +### 3.3.1 遗留问题影响以及规避措施 + +| 问题单号 | 问题描述 | 问题级别 | 问题影响和规避措施 | 当前状态 | +| -------- | -------- | -------- | ------------------ | -------- | +| N/A | | | | | + +### 3.3.2 问题统计 + +| | 问题总数 | 严重 | 主要 | 次要 | 不重要 | +| ------ | -------- | ---- | ---- | ---- | ------ | +| 数目 | 1 | 0 | 0 | 1 | 0 | +| 百分比 | 100% | 0 | 0 | 100% | 0 | + +### 3.3.3 问题单汇总 + +| 序号 | issue号 | 问题级别 | 问题简述 | 问题状态 | +| ---- | ------------------------------------------------------------ | -------- | ---------------------------------------------------- | -------- | +| 1 | [I5X7FD](https://e.gitee.com/opengaussorg/dashboard?issue=I5X7FD) | 次要 | date_add/date_sub函数,第二个参数不支持interval负数 | 已验收 | +| 2 | [I62V9L](https://e.gitee.com/opengaussorg/dashboard?issue=I62V9L) | 次要 | str_to_date函数前提条件不完整 | 已验收 | +| 3 | [I62WGS](https://e.gitee.com/opengaussorg/dashboard?issue=I62WGS) | 次要 | from_unixtime函数第二参数输入%l返回错误 | 已验收 | +| 4 | [I62LZC](https://e.gitee.com/opengaussorg/dashboard?issue=I62LZC) | 次要 | get_format()函数第一参数输入timestamp报错 | 已验收 | +| 5 | [I63EW6](https://e.gitee.com/opengaussorg/dashboard?issue=I63EW6) | 次要 | date_format函数第二参数输入%j、%U、%u、%V、%v、%X、%x返回值错误 | 已验收 | +| 6 | [I633BQ](https://e.gitee.com/opengaussorg/dashboard?issue=I633BQ) | 次要 | extract中from后参数、adddate第一参数不带引号输入0、101报错、date_format函数第一参数不带引号、extra第二参数不带引号输入date类型边界值外结果未报错、date_sub函数第一参数不带引号输入datetime格式解析错误 | 已验收 | +| 7 | [I64AZ9](https://e.gitee.com/opengaussorg/dashboard?issue=I64AZ9) | 次要 | timestampdiff函数不带引号输入datetime类型报错 | 已验收 | +| 8 | [I64D0P](https://e.gitee.com/opengaussorg/dashboard?issue=I64D0P) | 次要 | extract函数第一参数输入hour minute second microsecond,第二参数不带引号输入datetime格式报错 | 已验收 | +| 9 | [I649XP](https://e.gitee.com/opengaussorg/dashboard?issue=I649XP) | 次要 | extract函数第一参数输入组合参数,第二参数输入date或datetime格式返回错误 | 已验收 | +| 10 | [I62YR2](https://e.gitee.com/opengaussorg/dashboard?issue=I62YR2) | 次要 | extract函数第一参数为hour、minute、second、microsecond时,第二参数不带引号输入time类型报错 | 已验收 | +| 11 | [I61YDF](https://e.gitee.com/opengaussorg/dashboard?issue=I61YDF) | 次要 | adddate(exper, interval exper unit)、date_add(exper, interval exper unit)、date_sub(exper, interval exper unit)函数第二参数不支持算数运算表达式 | 已验收 | +| 12 | [I68FL7](https://e.gitee.com/opengaussorg/issues/table?issue=I68FL7) | 次要 | extract函数第一参数输入minute、hour、second、microsecond第二参数输入' '未报错 | 已验收 | +| 13 | [I6B20R](https://e.gitee.com/opengaussorg/issues/table?issue=I6B20R) | 次要 | date函数返回结果不支持算数运算 | 已验收 | +| 14 | [I6C4ZJ](https://e.gitee.com/opengaussorg/issues/table?issue=I6C4ZJ) | 次要 | date、adddate、date_add、date_sub、str_to_date、addtime函数返回类型错误 | 已验收 | +| 15 | [I6JZHX](https://e.gitee.com/opengaussorg/issues/table?issue=I6JZHX) | 次要 | 日期函数输入零值返回值受NO_ZERO_DATE参数控制文档中未说明 | 已验收 | +| 16 | [I6N626](https://e.gitee.com/opengaussorg/issues/table?issue=I6N626) | 次要 | date_format函数第一参数输入0报错 | 已验收 | + +# 4 测试执行 + +## 4.1 测试执行步骤 + +### 4.1.1 第一阶段函数用例测试 +| 测试步骤 | 测试结果 | +| ------------------------------------------------------------ | ---------------------------------- | +| 1. 在兼容B库并安装dolphin插件的环境
2. 以第一阶段函数用例作为输入测试函数执行结果 | 执行105条用例,输出结果均符合预期。 | +### 4.1.2 第二阶段函数用例测试 +| 测试步骤 | 测试结果 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| 1. 在兼容B库并安装dolphin插件的环境
2. 以第二阶段函数用例作为输入测试函数执行结果并插表与MySQL进行对比 | 执行437条用例,发现2个问题
现已进行处理,
1.有42条是小数秒进位在openGauss中是正常进位导致。(已经过Sig专家确认)
2.有18条是因为openGauss中不支持日期中含零导致的。(已经过Sig专家确认)
3.其余函数均符合预期 | +### 4.1.3 第三阶段函数用例测试 +| 测试步骤 | 测试结果 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| 1. 在兼容B库并安装dolphin插件的环境
2. 以第三阶段函数用例作为输入测试函数执行结果并插表与MySQL进行对比 | 执行372条用例,发现3个问题
1.addtime中有一条是openGauss自身省略时间末尾0导致,另一条是openGauss中time类型非严格模式时,限定范围为’838:59:59’。在函数参数中,对99991231解析时openGauss非严格模式将其认为是超范围时间,将其限定到’838:59:59’,而后参与运算,mysql则将其视为不合法时间。(已经过Sig专家确认)。
2.convert_tz中有18条是因为openGauss中时区比mysql中要多。(已经过Sig专家确认)
3.timestampdiff中有8条是因为,0年在openGauss中是闰年,在mysql中是平年,导致了运算日期差一天。(已经过Sig专家确认)
4.其余函数均符合预期。 | +### 4.1.4 第四阶段函数用例测试 +| 测试步骤 | 测试结果 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| 1. 在兼容B库并安装dolphin插件的环境
2. 以第四阶段严格模式函数用例与非严格模式测试用例作为输入测试函数执行结果并插表与MySQL进行对比 | 执行330条用例,发现1个问题
1.date_format中的3条用例都是openGauss中不再支持带零日期输入。(已经过Sig专家确认)
2.其余函数均符合预期。 | + +## 4.2 测试执行统计数据 + +| 版本名称 | 测试用例数 | 用例匹配结果 | +| ------------------------------ | ---------- | ----------------------------- | +| openGauss 3.1.0 build 5d56e686 | 1244 | Passed:1153
Failed:91 | + + +数据说明 + +累计发现用例匹配结果失败条,其中: +1. 共有42条是小数秒进位在openGauss中是正常进位导致。(已经过Sig专家确认) +2. 共有21条是因为openGauss中不支持日期中含零导致的。(已经过Sig专家确认) +3. addtime中有一条是openGauss自身省略时间末尾0导致。(已经过Sig专家确认) +4. addtime中还有在openGauss中time类型非严格模式时,限定范围为’838:59:59’。在函数参数中,对99991231解析时openGauss非严格模式将其认为是超范围时间,将其限定到’838:59:59’,而后参与运算,mysql则将其视为不合法时间。(已经过Sig专家确认) +5. convert_tz中有18条是因为openGauss中时区比mysql中要多。(已经过Sig专家确认) +6. timestampdiff中有8条是因为,0年在openGauss中是闰年,在mysql中是平年,导致了运算日期差一天。(已经过Sig专家确认) diff --git "a/Data_governance/\346\265\213\350\257\225\347\233\270\345\205\263/\346\265\213\350\257\225\346\226\207\346\241\243/openGauss\345\205\274\345\256\271MySQL\346\227\245\346\234\237\345\244\204\347\220\206\345\207\275\346\225\260\346\265\213\350\257\225\346\212\245\345\221\212.pdf" "b/Data_governance/\346\265\213\350\257\225\347\233\270\345\205\263/\346\265\213\350\257\225\346\226\207\346\241\243/openGauss\345\205\274\345\256\271MySQL\346\227\245\346\234\237\345\244\204\347\220\206\345\207\275\346\225\260\346\265\213\350\257\225\346\212\245\345\221\212.pdf" new file mode 100644 index 0000000000000000000000000000000000000000..c592d0a3c24ab046f920f8995c2cb4d28db48745 Binary files /dev/null and "b/Data_governance/\346\265\213\350\257\225\347\233\270\345\205\263/\346\265\213\350\257\225\346\226\207\346\241\243/openGauss\345\205\274\345\256\271MySQL\346\227\245\346\234\237\345\244\204\347\220\206\345\207\275\346\225\260\346\265\213\350\257\225\346\212\245\345\221\212.pdf" differ diff --git "a/Data_governance/\346\265\213\350\257\225\347\233\270\345\205\263/\346\265\213\350\257\225\346\226\271\346\241\210.docx" "b/Data_governance/\346\265\213\350\257\225\347\233\270\345\205\263/\346\265\213\350\257\225\346\226\271\346\241\210.docx" new file mode 100644 index 0000000000000000000000000000000000000000..28a3bfb9db6781733913cfaa96728ad609b104e0 Binary files /dev/null and "b/Data_governance/\346\265\213\350\257\225\347\233\270\345\205\263/\346\265\213\350\257\225\346\226\271\346\241\210.docx" differ diff --git "a/Data_governance/\346\265\213\350\257\225\347\233\270\345\205\263/\346\265\213\350\257\225\347\224\250\344\276\213/db_b_date_time_functions.sql" "b/Data_governance/\346\265\213\350\257\225\347\233\270\345\205\263/\346\265\213\350\257\225\347\224\250\344\276\213/db_b_date_time_functions.sql" new file mode 100644 index 0000000000000000000000000000000000000000..983e9e21ede41ddee9a971e66f60de659f3bc8a2 --- /dev/null +++ "b/Data_governance/\346\265\213\350\257\225\347\233\270\345\205\263/\346\265\213\350\257\225\347\224\250\344\276\213/db_b_date_time_functions.sql" @@ -0,0 +1,157 @@ +create schema b_datetime_func_test1; +set current_schema to 'b_datetime_func_test1'; +set datestyle = 'ISO,ymd'; +set time zone "Asia/Shanghai"; +-- test part-one function +-- test curdate() +select curdate(); + +-- test current_time(precision) +select current_time; +select current_time(); +select current_time(0); +select current_time(1); +select current_time(2); +select current_time(3); +select current_time(4); +select current_time(5); +select current_time(6); +select current_time(7); + +-- test curtime(precision) +select curtime; +select curtime(); +select curtime(0); +select curtime(1); +select curtime(2); +select curtime(3); +select curtime(4); +select curtime(5); +select curtime(6); +select curtime(7); + +-- test current_timestamp(precision) + +select current_timestamp; +select current_timestamp(); +select current_timestamp(0); +select current_timestamp(1); +select current_timestamp(2); +select current_timestamp(3); +select current_timestamp(4); +select current_timestamp(5); +select current_timestamp(6); +select current_timestamp(7); + +-- test localtime(precision) +select localtime; +select localtime(); +select localtime(0); +select localtime(1); +select localtime(2); +select localtime(3); +select localtime(4); +select localtime(5); +select localtime(6); +select localtime(7); + +-- test localtimestamp(precision) +select localtimestamp; +select localtimestamp(); +select localtimestamp(0); +select localtimestamp(1); +select localtimestamp(2); +select localtimestamp(3); +select localtimestamp(4); +select localtimestamp(5); +select localtimestamp(6); +select localtimestamp(7); + +-- test now(precision) +-- when the GUC variable b_db_timestamp = 0, now returns the current date and time +show dolphin.b_db_timestamp; +select now(); +select now(0); +select now(1); +select now(2); +select now(3); +select now(4); +select now(5); +select now(6); +select now(7); + +-- when the GUC variable b_db_timestamp != 0, now returns the timestamp according to b_db_timestamp +set dolphin.b_db_timestamp = 0.1; +set dolphin.b_db_timestamp = 2147483647.1; +set dolphin.b_db_timestamp = 1.1234; +select now(); +select now(0); +select now(1); +select now(2); +select now(3); +select now(4); +select now(5); +select now(6); +select now(7); +set dolphin.b_db_timestamp = 0.0; + +-- test sysdate(precision) +select sysdate; +select sysdate(); +select sysdate(0); +select sysdate(1); +select sysdate(2); +select sysdate(3); +select sysdate(4); +select sysdate(5); +select sysdate(6); +select sysdate(7); + +-- test insert +create table test_date(col date); +insert into test_date values(curdate()); +select * from test_date; +drop table test_date; +create table test_time(col time); +insert into test_time values(current_time); +insert into test_time values(current_time()); +insert into test_time values(current_time(0)); +insert into test_time values(current_time(6)); +select * from test_time; +delete from test_time; +insert into test_time values(curtime()); +insert into test_time values(curtime(0)); +insert into test_time values(curtime(6)); +select * from test_time; +drop table test_time; +create table test_datetime(col datetime); +insert into test_datetime values(current_timestamp); +insert into test_datetime values(current_timestamp()); +insert into test_datetime values(current_timestamp(0)); +insert into test_datetime values(current_timestamp(6)); +select * from test_datetime; +delete from test_datetime; +insert into test_datetime values(localtime); +insert into test_datetime values(localtime()); +insert into test_datetime values(localtime(0)); +insert into test_datetime values(localtime(6)); +select * from test_datetime; +delete from test_datetime; +insert into test_datetime values(localtimestamp); +insert into test_datetime values(localtimestamp()); +insert into test_datetime values(localtimestamp(0)); +insert into test_datetime values(localtimestamp(6)); +select * from test_datetime; +delete from test_datetime; +insert into test_datetime values(now()); +insert into test_datetime values(now(0)); +insert into test_datetime values(now(6)); +select * from test_datetime; +delete from test_datetime; +insert into test_datetime values(sysdate()); +insert into test_datetime values(sysdate(0)); +insert into test_datetime values(sysdate(6)); +select * from test_datetime; +drop table test_datetime; +drop schema b_datetime_func_test1 cascade; +reset current_schema; \ No newline at end of file diff --git "a/Data_governance/\346\265\213\350\257\225\347\233\270\345\205\263/\346\265\213\350\257\225\347\224\250\344\276\213/db_b_date_time_functions2.sql" "b/Data_governance/\346\265\213\350\257\225\347\233\270\345\205\263/\346\265\213\350\257\225\347\224\250\344\276\213/db_b_date_time_functions2.sql" new file mode 100644 index 0000000000000000000000000000000000000000..c1c373184bae5556b4247610169eff3deee19e3d --- /dev/null +++ "b/Data_governance/\346\265\213\350\257\225\347\233\270\345\205\263/\346\265\213\350\257\225\347\224\250\344\276\213/db_b_date_time_functions2.sql" @@ -0,0 +1,632 @@ +---- b compatibility case +drop database if exists b_datetime_func_test2; +create database b_datetime_func_test2 encoding 'UTF-8' lc_collate 'C' lc_ctype 'C' dbcompatibility 'B'; +\c b_datetime_func_test2 +set datestyle = 'ISO,ymd'; +set time zone "Asia/Shanghai"; +create table test(funcname text, result text); +-- test part-two function +-- test dayname +alter system set dolphin.lc_time_names = 'en_US'; +show dolphin.lc_time_names; +-- 严格模式或者非严格模式都有值 +-- 功能 +insert into test values('dayname(''2021-11-12'')', dayname('2021-11-12')); +insert into test values('dayname(''2021-11-13'')', dayname('2021-11-13')); +insert into test values('dayname(''2021-11-14'')', dayname('2021-11-14')); +insert into test values('dayname(''2021-11-15'')', dayname('2021-11-15')); +insert into test values('dayname(''2021-11-16'')', dayname('2021-11-16')); +insert into test values('dayname(''2021-11-17'')', dayname('2021-11-17')); +insert into test values('dayname(''2021-11-18'')', dayname('2021-11-18')); +insert into test values('dayname(''0000-1-1 23:59:59.9999995'')', dayname('0000-1-1 23:59:59.9999995')); +insert into test values('dayname(''0000-12-31 22:59:59.9999995'')', dayname('0000-12-31 22:59:59.9999995')); +insert into test values('dayname(''0000-12-31 23:59:59.9999995'')', dayname('0000-12-31 23:59:59.9999995')); +-- 边界 +insert into test values('dayname(''0000-1-1'')', dayname('0000-1-1')); +insert into test values('dayname(''9999-12-31'')', dayname('9999-12-31')); +insert into test values('dayname(''0000-1-1 00:00:00'')', dayname('0000-1-1 00:00:00')); +insert into test values('dayname(''9999-12-31 23:59:59.999999'')', dayname('9999-12-31 23:59:59.999999')); +-- 类型 +insert into test values('dayname(date''0000-1-1'')', dayname(date'0000-1-1')); +insert into test values('dayname(cast(''9999-12-31 12:12:12'' as datetime))', dayname(cast('9999-12-31 12:12:12' as datetime))); +insert into test values('dayname(101)', dayname(101)); +insert into test values('dayname(99991231)', dayname(99991231)); +insert into test values('dayname(99991231235959.999999)', dayname(99991231235959.999999)); +insert into test values('dayname(20211112235959.999999)', dayname(20211112235959.999999)); +insert into test values('dayname(20211112235959.9999999)', dayname(20211112235959.9999999)); +-- 特异 +insert into test values('dayname(null)', dayname(null)); + +-- 非严格模式,参数不合法,报warning,返回NULL或者对应值 +set dolphin.sql_mode = 'sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('dayname(''10000-1-1'')', dayname('10000-1-1')); +insert into test values('dayname(''9999-12-31 23:59:59.9999995'')', dayname('9999-12-31 23:59:59.9999995')); +insert into test values('dayname(-1)', dayname(-1)); +insert into test values('dayname(0)', dayname(0)); +insert into test values('dayname(100000101)', dayname(100000101)); +insert into test values('dayname(99991231235959.9999995)', dayname(99991231235959.9999995)); +insert into test values('dayname(9999999999999999999999)', dayname(9999999999999999999999)); + +-- 严格模式,参数不合法,抛出错误 +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('dayname(''10000-1-1'')', dayname('10000-1-1')); +insert into test values('dayname(''9999-12-31 23:59:59.9999995'')', dayname('9999-12-31 23:59:59.9999995')); +insert into test values('dayname(-1)', dayname(-1)); +insert into test values('dayname(0)', dayname(0)); +insert into test values('dayname(100000101)', dayname(100000101)); +insert into test values('dayname(99991231235959.9999995)', dayname(99991231235959.9999995)); +insert into test values('dayname(9999999999999999999999)', dayname(9999999999999999999999)); + +-- test monthname +alter system set dolphin.lc_time_names = 'en_US'; +show dolphin.lc_time_names; +-- 严格模式或者非严格模式都有值 +-- 功能 +insert into test values('monthname(''2021-1-1'')', monthname('2021-1-1')); +insert into test values('monthname(''2021-2-1'')', monthname('2021-2-1')); +insert into test values('monthname(''2021-3-1'')', monthname('2021-3-1')); +insert into test values('monthname(''2021-4-1'')', monthname('2021-4-1')); +insert into test values('monthname(''2021-5-1'')', monthname('2021-5-1')); +insert into test values('monthname(''2021-6-1'')', monthname('2021-6-1')); +insert into test values('monthname(''2021-7-1'')', monthname('2021-7-1')); +insert into test values('monthname(''2021-8-1'')', monthname('2021-8-1')); +insert into test values('monthname(''2021-9-1'')', monthname('2021-9-1')); +insert into test values('monthname(''2021-10-1'')', monthname('2021-10-1')); +insert into test values('monthname(''2021-11-1'')', monthname('2021-11-1')); +insert into test values('monthname(''2021-12-1'')', monthname('2021-12-1')); +insert into test values('monthname(''0000-1-1 23:59:59.9999995'')', monthname('0000-1-1 23:59:59.9999995')); +insert into test values('monthname(''0000-12-31 22:59:59.9999995'')', monthname('0000-12-31 22:59:59.9999995')); +insert into test values('monthname(''0000-12-31 23:59:59.9999995'')', monthname('0000-12-31 23:59:59.9999995')); +-- 边界 +insert into test values('monthname(''0000-1-1'')', monthname('0000-1-1')); +insert into test values('monthname(''9999-12-31'')', monthname('9999-12-31')); +insert into test values('monthname(''0000-1-1 00:00:00'')', monthname('0000-1-1 00:00:00')); +insert into test values('monthname(''9999-12-31 23:59:59.999999'')', monthname('9999-12-31 23:59:59.999999')); +-- 类型 +insert into test values('monthname(date''0000-1-1'')', monthname(date'0000-1-1')); +insert into test values('monthname(cast(''9999-12-31 12:12:12'' as datetime))', monthname(cast('9999-12-31 12:12:12' as datetime))); +insert into test values('monthname(101)', monthname(101)); +insert into test values('monthname(99991231)', monthname(99991231)); +insert into test values('monthname(99991231235959.999999)', monthname(99991231235959.999999)); +insert into test values('monthname(20211112235959.999999)', monthname(20211112235959.999999)); +insert into test values('monthname(20211112235959.9999999)', monthname(20211112235959.9999999)); +-- 特异 +insert into test values('monthname(null)', monthname(null)); +insert into test values('monthname(''2021-00-01'')', monthname('2021-00-01')); +insert into test values('monthname(20210001)', monthname(20210001)); +insert into test values('monthname(0)', monthname(0)); +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes'; +insert into test values('monthname(''0000-00-00'')', monthname('0000-00-00')); +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('monthname(''0000-00-00'')', monthname('0000-00-00')); + +-- 非严格模式,参数不合法,报warning,返回NULL或者对应值 +set dolphin.sql_mode = 'sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('monthname(''10000-1-1'')', monthname('10000-1-1')); +insert into test values('monthname(''9999-12-31 23:59:59.9999995'')', monthname('9999-12-31 23:59:59.9999995')); +insert into test values('monthname(-1)', monthname(-1)); +insert into test values('monthname(100000101)', monthname(100000101)); +insert into test values('monthname(99991231235959.9999995)', monthname(99991231235959.9999995)); +insert into test values('monthname(9999999999999999999999)', monthname(9999999999999999999999)); + +-- 严格模式,参数不合法,抛出错误 +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('monthname(''10000-1-1'')', monthname('10000-1-1')); +insert into test values('monthname(''9999-12-31 23:59:59.9999995'')', monthname('9999-12-31 23:59:59.9999995')); +insert into test values('monthname(-1)', monthname(-1)); +insert into test values('monthname(100000101)', monthname(100000101)); +insert into test values('monthname(99991231235959.9999995)', monthname(99991231235959.9999995)); +insert into test values('monthname(9999999999999999999999)', monthname(9999999999999999999999)); + +-- test lc_time_names +alter system set dolphin.lc_time_names = 'en_US'; +select pg_sleep(1); +show dolphin.lc_time_names; +select dayname('2021-11-12'); +select monthname('2021-11-12'); +alter system set dolphin.lc_time_names = 'zh_CN'; +select pg_sleep(1); +select dayname('2021-11-12'); +select monthname('2021-11-12'); +alter system set dolphin.lc_time_names = 'aaa'; +alter system set dolphin.lc_time_names = 'en_US'; +select pg_sleep(1); + +-- test time_to_sec +-- 严格模式或者非严格模式都有值 +-- 功能 +insert into test values('time_to_sec(''00:00:00'')', time_to_sec('00:00:00')); +insert into test values('time_to_sec(''00:00:01'')', time_to_sec('00:00:01')); +insert into test values('time_to_sec(''-00:00:01'')', time_to_sec('-00:00:01')); +insert into test values('time_to_sec(''12:12:12.1'')', time_to_sec('12:12:12.1')); +insert into test values('time_to_sec(''-12:12:12.1'')', time_to_sec('-12:12:12.1')); +insert into test values('time_to_sec(''111:12:12.1'')', time_to_sec('111:12:12.1')); +insert into test values('time_to_sec(''-111:12:12.1'')', time_to_sec('-111:12:12.1')); +insert into test values('time_to_sec(''2021-11-12 00:00:00'')', time_to_sec('2021-11-12 00:00:00')); +insert into test values('time_to_sec(''2021-11-12 12:12:12'')', time_to_sec('2021-11-12 12:12:12')); +insert into test values('time_to_sec(''2021-11-12 23:59:59'')', time_to_sec('2021-11-12 23:59:59')); +insert into test values('time_to_sec(''2021-11-12 23:59:59.9999995'')', time_to_sec('2021-11-12 23:59:59.9999995')); +-- 边界 +insert into test values('time_to_sec(''838:59:59'')', time_to_sec('838:59:59')); +insert into test values('time_to_sec(''-838:59:59'')', time_to_sec('-838:59:59')); +insert into test values('time_to_sec(''34 22:59:59'')', time_to_sec('34 22:59:59')); +insert into test values('time_to_sec(''-34 22:59:59'')', time_to_sec('-34 22:59:59')); +-- 类型 +insert into test values('time_to_sec(date''2021-11-12'')', time_to_sec(date'2021-11-12')); +insert into test values('time_to_sec(cast(''9999-12-31 12:12:12'' as datetime))', time_to_sec(cast('9999-12-31 12:12:12' as datetime))); +insert into test values('time_to_sec(-1)', time_to_sec(-1)); +insert into test values('time_to_sec(0)', time_to_sec(0)); +insert into test values('time_to_sec(1)', time_to_sec(1)); +insert into test values('time_to_sec(-8385959)', time_to_sec(-8385959)); +insert into test values('time_to_sec(8385959)', time_to_sec(8385959)); +-- 特异 +insert into test values('time_to_sec(null)', time_to_sec(null)); + +-- 非严格模式,参数不合法,报warning,返回NULL或者对应值边界值 +set dolphin.sql_mode = 'sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('time_to_sec(''00:00:60'')', time_to_sec('00:00:60')); +insert into test values('time_to_sec(''00:60:00'')', time_to_sec('00:60:00')); +insert into test values('time_to_sec(''838:59:59.1'')', time_to_sec('838:59:59.1')); +insert into test values('time_to_sec(''-838:59:59.1'')', time_to_sec('-838:59:59.1')); +insert into test values('time_to_sec(''839:00:00'')', time_to_sec('839:00:00')); +insert into test values('time_to_sec(''-839:00:00'')', time_to_sec('-839:00:00')); +insert into test values('time_to_sec(''34 22:59:59.1'')', time_to_sec('34 22:59:59.1')); +insert into test values('time_to_sec(''-34 22:59:59.1'')', time_to_sec('-34 22:59:59.1')); +insert into test values('time_to_sec(''34 23:00:00'')', time_to_sec('34 23:00:00')); +insert into test values('time_to_sec(''-34 23:00:00'')', time_to_sec('-34 23:00:00')); + +-- 严格模式,参数不合法,抛出错误 +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('time_to_sec(''00:00:60'')', time_to_sec('00:00:60')); +insert into test values('time_to_sec(''00:60:00'')', time_to_sec('00:60:00')); +insert into test values('time_to_sec(''838:59:59.1'')', time_to_sec('838:59:59.1')); +insert into test values('time_to_sec(''-838:59:59.1'')', time_to_sec('-838:59:59.1')); +insert into test values('time_to_sec(''839:00:00'')', time_to_sec('839:00:00')); +insert into test values('time_to_sec(''-839:00:00'')', time_to_sec('-839:00:00')); +insert into test values('time_to_sec(''34 22:59:59.1'')', time_to_sec('34 22:59:59.1')); +insert into test values('time_to_sec(''-34 22:59:59.1'')', time_to_sec('-34 22:59:59.1')); +insert into test values('time_to_sec(''34 23:00:00'')', time_to_sec('34 23:00:00')); +insert into test values('time_to_sec(''-34 23:00:00'')', time_to_sec('-34 23:00:00')); + +-- test month +-- 严格模式或者非严格模式都有值 +-- 功能 +insert into test values('month(''2021-1-1'')', month('2021-1-1')); +insert into test values('month(''2021-2-1'')', month('2021-2-1')); +insert into test values('month(''2021-3-1'')', month('2021-3-1')); +insert into test values('month(''2021-4-1'')', month('2021-4-1')); +insert into test values('month(''2021-5-1'')', month('2021-5-1')); +insert into test values('month(''2021-6-1'')', month('2021-6-1')); +insert into test values('month(''2021-7-1'')', month('2021-7-1')); +insert into test values('month(''2021-8-1'')', month('2021-8-1')); +insert into test values('month(''2021-9-1'')', month('2021-9-1')); +insert into test values('month(''2021-10-1'')', month('2021-10-1')); +insert into test values('month(''2021-11-1'')', month('2021-11-1')); +insert into test values('month(''2021-12-1'')', month('2021-12-1')); +insert into test values('month(''0000-1-1 23:59:59.9999995'')', month('0000-1-1 23:59:59.9999995')); +insert into test values('month(''0000-12-31 22:59:59.9999995'')', month('0000-12-31 22:59:59.9999995')); +insert into test values('month(''0000-12-31 23:59:59.9999995'')', month('0000-12-31 23:59:59.9999995')); +insert into test values('month(''0000-1-1'')', month('0000-1-1')); +insert into test values('month(''9999-12-31'')', month('9999-12-31')); +insert into test values('month(''0000-1-1 00:00:00'')', month('0000-1-1 00:00:00')); +insert into test values('month(''9999-12-31 23:59:59.999999'')', month('9999-12-31 23:59:59.999999')); +-- 类型 +insert into test values('month(date''0000-1-1'')', month(date'0000-1-1')); +insert into test values('month(cast(''9999-12-31 12:12:12'' as datetime))', month(cast('9999-12-31 12:12:12' as datetime))); +insert into test values('month(101)', month(101)); +insert into test values('month(99991231)', month(99991231)); +insert into test values('month(99991231235959.999999)', month(99991231235959.999999)); +insert into test values('month(20211112235959.999999)', month(20211112235959.999999)); +insert into test values('month(20211112235959.9999999)', month(20211112235959.9999999)); +-- 特异 +insert into test values('month(null)', month(null)); +insert into test values('month(''2021-00-01'')', month('2021-00-01')); +insert into test values('month(''2021-01-00'')', month('2021-01-00')); +insert into test values('month(''2021-00-00'')', month('2021-00-00')); +insert into test values('month(20210001)', month(20210001)); +insert into test values('month(20210100)', month(20210100)); +insert into test values('month(20210000)', month(20210000)); +insert into test values('month(0)', month(0)); +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes'; +insert into test values('month(''0000-00-00'')', month('0000-00-00')); +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('month(''0000-00-00'')', month('0000-00-00')); + +-- 非严格模式,参数不合法,报warning,返回NULL或者对应值 +set dolphin.sql_mode = 'sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('month(''10000-1-1'')', month('10000-1-1')); +insert into test values('month(''9999-12-31 23:59:59.9999995'')', month('9999-12-31 23:59:59.9999995')); +insert into test values('month(-1)', month(-1)); +insert into test values('month(100000101)', month(100000101)); +insert into test values('month(99991231235959.9999995)', month(99991231235959.9999995)); +insert into test values('month(9999999999999999999999)', month(9999999999999999999999)); + +-- 严格模式,参数不合法,抛出错误 +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('month(''10000-1-1'')', month('10000-1-1')); +insert into test values('month(''9999-12-31 23:59:59.9999995'')', month('9999-12-31 23:59:59.9999995')); +insert into test values('month(-1)', month(-1)); +insert into test values('month(100000101)', month(100000101)); +insert into test values('month(99991231235959.9999995)', month(99991231235959.9999995)); +insert into test values('month(9999999999999999999999)', month(9999999999999999999999)); + +-- test last_day +set dolphin.b_compatibility_mode = true; +-- 严格模式或者非严格模式都有值 +-- 功能 +insert into test values('last_day(''0000-2-1'')', last_day('0000-2-1')); +insert into test values('last_day(''2021-1-1'')', last_day('2021-1-1')); +insert into test values('last_day(''2021-2-1'')', last_day('2021-2-1')); +insert into test values('last_day(''2021-3-1'')', last_day('2021-3-1')); +insert into test values('last_day(''2021-4-1'')', last_day('2021-4-1')); +insert into test values('last_day(''2021-5-1'')', last_day('2021-5-1')); +insert into test values('last_day(''2021-6-1'')', last_day('2021-6-1')); +insert into test values('last_day(''2021-7-1'')', last_day('2021-7-1')); +insert into test values('last_day(''2021-8-1'')', last_day('2021-8-1')); +insert into test values('last_day(''2021-9-1'')', last_day('2021-9-1')); +insert into test values('last_day(''2021-10-1'')', last_day('2021-10-1')); +insert into test values('last_day(''2021-11-1'')', last_day('2021-11-1')); +insert into test values('last_day(''2021-12-1'')', last_day('2021-12-1')); +insert into test values('last_day(''0000-12-31 23:59:59.9999995'')', last_day('0000-12-31 23:59:59.9999995')); +-- 边界 +insert into test values('last_day(''0000-1-1'')', last_day('0000-1-1')); +insert into test values('last_day(''9999-12-31'')', last_day('9999-12-31')); +insert into test values('last_day(''0000-1-1 00:00:00'')', last_day('0000-1-1 00:00:00')); +insert into test values('last_day(''9999-12-31 23:59:59.999999'')', last_day('9999-12-31 23:59:59.999999')); +-- 类型 +insert into test values('last_day(date''0000-1-1'')', last_day(date'0000-1-1')); +insert into test values('last_day(cast(''9999-12-31 12:12:12'' as datetime))', last_day(cast('9999-12-31 12:12:12' as datetime))); +insert into test values('last_day(101)', last_day(101)); +insert into test values('last_day(99991231)', last_day(99991231)); +insert into test values('last_day(99991231235959.999999)', last_day(99991231235959.999999)); +insert into test values('last_day(20211112235959.999999)', last_day(20211112235959.999999)); +insert into test values('last_day(20211112235959.9999999)', last_day(20211112235959.9999999)); +-- 特异 +insert into test values('last_day(null)', last_day(null)); +insert into test values('last_day(''2021-01-00'')', last_day('2021-01-00')); +insert into test values('last_day(20210100)', last_day(20210100)); + +-- 非严格模式,参数不合法,报warning,返回NULL或者对应值 +set dolphin.sql_mode = 'sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('last_day(''2021-00-01'')', last_day('2021-00-01')); +insert into test values('last_day(20210001)', last_day(20210001)); +insert into test values('last_day(''0000-1-1 23:59:59.9999995'')', last_day('0000-1-1 23:59:59.9999995')); +insert into test values('last_day(''0000-12-31 22:59:59.9999995'')', last_day('0000-12-31 22:59:59.9999995')); +insert into test values('last_day(''10000-1-1'')', last_day('10000-1-1')); +insert into test values('last_day(''9999-12-31 23:59:59.9999995'')', last_day('9999-12-31 23:59:59.9999995')); +insert into test values('last_day(-1)', last_day(-1)); +insert into test values('last_day(0)', last_day(0)); +insert into test values('last_day(100000101)', last_day(100000101)); +insert into test values('last_day(99991231235959.9999995)', last_day(99991231235959.9999995)); +insert into test values('last_day(9999999999999999999999)', last_day(9999999999999999999999)); + +-- 严格模式,参数不合法,抛出错误 +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('last_day(''2021-00-01'')', last_day('2021-00-01')); +insert into test values('last_day(20210001)', last_day(20210001)); +insert into test values('last_day(''0000-1-1 23:59:59.9999995'')', last_day('0000-1-1 23:59:59.9999995')); +insert into test values('last_day(''0000-12-31 22:59:59.9999995'')', last_day('0000-12-31 22:59:59.9999995')); +insert into test values('last_day(''10000-1-1'')', last_day('10000-1-1')); +insert into test values('last_day(''9999-12-31 23:59:59.9999995'')', last_day('9999-12-31 23:59:59.9999995')); +insert into test values('last_day(-1)', last_day(-1)); +insert into test values('last_day(0)', last_day(0)); +insert into test values('last_day(100000101)', last_day(100000101)); +insert into test values('last_day(99991231235959.9999995)', last_day(99991231235959.9999995)); +insert into test values('last_day(9999999999999999999999)', last_day(9999999999999999999999)); +set dolphin.b_compatibility_mode = false; + +-- test date +-- 严格模式或者非严格模式都有值 +-- 功能 +insert into test values('date(''2021-1-1'')', date('2021-1-1')); +insert into test values('date(''2021-1-1 23:59:59'')', date('2021-1-1 23:59:59')); +insert into test values('date(''2021-1-1 23:59:59.9999995'')', date('2021-1-1 23:59:59.9999995')); +-- 边界 +insert into test values('date(''0000-1-1'')', date('0000-1-1')); +insert into test values('date(''9999-12-31'')', date('9999-12-31')); +insert into test values('date(''0000-1-1 00:00:00'')', date('0000-1-1 00:00:00')); +insert into test values('date(''9999-12-31 23:59:59.999999'')', date('9999-12-31 23:59:59.999999')); +insert into test values('date(''0000-1-1 23:59:59.9999995'')', date('0000-1-1 23:59:59.9999995')); +insert into test values('date(''0000-12-31 22:59:59.9999995'')', date('0000-12-31 22:59:59.9999995')); +insert into test values('date(''0000-12-31 23:59:59.9999995'')', date('0000-12-31 23:59:59.9999995')); +-- 类型 +insert into test values('date(date''0000-1-1'')', date(date'0000-1-1')); +insert into test values('date(cast(''9999-12-31 12:12:12'' as datetime))', date(cast('9999-12-31 12:12:12' as datetime))); +insert into test values('date(101)', date(101)); +insert into test values('date(99991231)', date(99991231)); +insert into test values('date(99991231235959.999999)', date(99991231235959.999999)); +insert into test values('date(20211112235959.999999)', date(20211112235959.999999)); +insert into test values('date(20211112235959.9999999)', date(20211112235959.9999999)); +-- 特异 +insert into test values('date(null)', date(null)); +insert into test values('date(''2021-1-0'')', date('2021-1-0')); +insert into test values('date(''2021-0-1'')', date('2021-0-1')); +insert into test values('date(''2021-0-0'')', date('2021-0-0')); +insert into test values('date(0)', date(0)); +insert into test values('date(20210031)', date(20210031)); +insert into test values('date(20210100)', date(20210100)); +insert into test values('date(20210100)', date(20210100)); +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('date(''0000-00-00'')', date('0000-00-00')); +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes'; +insert into test values('date(''0000-00-00'')', date('0000-00-00')); + +-- 非严格模式,参数不合法,报warning,返回NULL或者对应值 +set dolphin.sql_mode = 'sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('date(''10000-1-1'')', date('10000-1-1')); +insert into test values('date(''9999-12-31 23:59:59.9999995'')', date('9999-12-31 23:59:59.9999995')); +insert into test values('date(-1)', date(-1)); +insert into test values('date(100000101)', date(100000101)); +insert into test values('date(99991231235959.9999995)', date(99991231235959.9999995)); +insert into test values('date(9999999999999999999999)', date(9999999999999999999999)); + +-- 严格模式,参数不合法,抛出错误 +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('date(''10000-1-1'')', date('10000-1-1')); +insert into test values('date(''9999-12-31 23:59:59.9999995'')', date('9999-12-31 23:59:59.9999995')); +insert into test values('date(-1)', date(-1)); +insert into test values('date(100000101)', date(100000101)); +insert into test values('date(99991231235959.9999995)', date(99991231235959.9999995)); +insert into test values('date(9999999999999999999999)', date(9999999999999999999999)); + +-- test day +-- 严格模式或者非严格模式都有值 +-- 功能 +insert into test values('day(''2021-1-1'')', day('2021-1-1')); +insert into test values('day(''2021-1-1 00:00:00'')', day('2021-1-1 00:00:00')); +insert into test values('day(''2021-1-1 23:59:59.9999995'')', day('2021-1-1 23:59:59.9999995')); +insert into test values('day(''0000-1-1 23:59:59.9999995'')', day('0000-1-1 23:59:59.9999995')); +insert into test values('day(''0000-12-31 22:59:59.9999995'')', day('0000-12-31 22:59:59.9999995')); +insert into test values('day(''0000-12-31 23:59:59.9999995'')', day('0000-12-31 23:59:59.9999995')); +-- 边界 +insert into test values('day(''0000-1-1'')', day('0000-1-1')); +insert into test values('day(''9999-12-31'')', day('9999-12-31')); +insert into test values('day(''0000-1-1 00:00:00'')', day('0000-1-1 00:00:00')); +insert into test values('day(''9999-12-31 23:59:59.999999'')', day('9999-12-31 23:59:59.999999')); +-- 类型 +insert into test values('day(date''0000-1-1'')', day(date'0000-1-1')); +insert into test values('day(cast(''9999-12-31 12:12:12'' as datetime))', day(cast('9999-12-31 12:12:12' as datetime))); +insert into test values('day(101)', day(101)); +insert into test values('day(99991231)', day(99991231)); +insert into test values('day(99991231235959.999999)', day(99991231235959.999999)); +insert into test values('day(20211112235959.999999)', day(20211112235959.999999)); +insert into test values('day(20211112235959.9999999)', day(20211112235959.9999999)); +-- 特异 +insert into test values('day(null)', day(null)); +insert into test values('day(''2021-00-01'')', day('2021-00-01')); +insert into test values('day(''2021-01-00'')', day('2021-01-00')); +insert into test values('day(''2021-00-00'')', day('2021-00-00')); +insert into test values('day(20210001)', day(20210001)); +insert into test values('day(20210100)', day(20210100)); +insert into test values('day(20210000)', day(20210000)); +insert into test values('day(0)', day(0)); +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('day(''0000-00-00'')', day('0000-00-00')); +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes'; +insert into test values('day(''0000-00-00'')', day('0000-00-00')); + +-- 非严格模式,参数不合法,报warning,返回NULL或者对应值 +set dolphin.sql_mode = 'sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('day(''10000-1-1'')', day('10000-1-1')); +insert into test values('day(''9999-12-31 23:59:59.9999995'')', day('9999-12-31 23:59:59.9999995')); +insert into test values('day(-1)', day(-1)); +insert into test values('day(100000101)', day(100000101)); +insert into test values('day(99991231235959.9999995)', day(99991231235959.9999995)); +insert into test values('day(9999999999999999999999)', day(9999999999999999999999)); + +-- 严格模式,参数不合法,抛出错误 +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('day(''10000-1-1'')', day('10000-1-1')); +insert into test values('day(''9999-12-31 23:59:59.9999995'')', day('9999-12-31 23:59:59.9999995')); +insert into test values('day(-1)', day(-1)); +insert into test values('day(100000101)', day(100000101)); +insert into test values('day(99991231235959.9999995)', day(99991231235959.9999995)); +insert into test values('day(9999999999999999999999)', day(9999999999999999999999)); + +--test week +-- 严格模式或者非严格模式都有值 +-- 单参数-功能 +alter system set dolphin.default_week_format = 0; +select pg_sleep(1); +show dolphin.default_week_format; +insert into test values('week(''2000-1-1'')', week('2000-1-1')); +alter system set dolphin.default_week_format = 1; +select pg_sleep(1); +show dolphin.default_week_format; +insert into test values('week(''2000-1-1'')', week('2000-1-1')); +alter system set dolphin.default_week_format = 2; +select pg_sleep(1); +show dolphin.default_week_format; +insert into test values('week(''2000-1-1'')', week('2000-1-1')); +alter system set dolphin.default_week_format = 3; +select pg_sleep(1); +show dolphin.default_week_format; +insert into test values('week(''2000-1-1'')', week('2000-1-1')); +alter system set dolphin.default_week_format = 4; +select pg_sleep(1); +show dolphin.default_week_format; +insert into test values('week(''2000-1-1'')', week('2000-1-1')); +alter system set dolphin.default_week_format = 5; +select pg_sleep(1); +show dolphin.default_week_format; +insert into test values('week(''2000-1-1'')', week('2000-1-1')); +alter system set dolphin.default_week_format = 6; +select pg_sleep(1); +show dolphin.default_week_format; +insert into test values('week(''2000-1-1'')', week('2000-1-1')); +alter system set dolphin.default_week_format = 7; +select pg_sleep(1); +show dolphin.default_week_format; +insert into test values('week(''2000-1-1'')', week('2000-1-1')); +-- 单参数-边界 +alter system set dolphin.default_week_format = 0; +select pg_sleep(1); +show dolphin.default_week_format; +insert into test values('week(''0000-1-1'')', week('0000-1-1')); +insert into test values('week(''9999-12-31'')', week('9999-12-31')); +insert into test values('week(''0000-1-1 00:00:00'')', week('0000-1-1 00:00:00')); +insert into test values('week(''9999-12-31 23:59:59.999999'')', week('9999-12-31 23:59:59.999999')); +insert into test values('week(''0000-12-31 23:59:59.9999995'')', week('0000-12-31 23:59:59.9999995')); +-- 单参数-类型 +insert into test values('week(date''0000-1-1'')', week(date'0000-1-1')); +insert into test values('week(cast(''9999-12-31 12:12:12'' as datetime))', week(cast('9999-12-31 12:12:12' as datetime))); +insert into test values('week(101)', week(101)); +insert into test values('week(99991231)', week(99991231)); +insert into test values('week(99991231235959.999999)', week(99991231235959.999999)); +insert into test values('week(20211112235959.999999)', week(20211112235959.999999)); +insert into test values('week(20211112235959.9999999)', week(20211112235959.9999999)); +-- 单参数-特异 +insert into test values('week(null)', week(null)); + +-- 单参数-非严格模式,参数不合法,报warning,返回NULL或者对应值 +set dolphin.sql_mode = 'sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('week(''10000-1-1'')', week('10000-1-1')); +insert into test values('week(''9999-12-31 23:59:59.9999995'')', week('9999-12-31 23:59:59.9999995')); +insert into test values('week(0)', week(0)); +insert into test values('week(-1)', week(-1)); +insert into test values('week(100000101)', week(100000101)); +insert into test values('week(99991231235959.9999995)', week(99991231235959.9999995)); +insert into test values('week(9999999999999999999999)', week(9999999999999999999999)); +insert into test values('week(''0000-1-1 23:59:59.9999995'')', week('0000-1-1 23:59:59.9999995')); +insert into test values('week(''0000-12-31 22:59:59.9999995'')', week('0000-12-31 22:59:59.9999995')); + +-- 单参数-严格模式,参数不合法,抛出错误 +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('week(''10000-1-1'')', week('10000-1-1')); +insert into test values('week(''9999-12-31 23:59:59.9999995'')', week('9999-12-31 23:59:59.9999995')); +insert into test values('week(0)', week(0)); +insert into test values('week(-1)', week(-1)); +insert into test values('week(100000101)', week(100000101)); +insert into test values('week(99991231235959.9999995)', week(99991231235959.9999995)); +insert into test values('week(9999999999999999999999)', week(9999999999999999999999)); +insert into test values('week(''0000-1-1 23:59:59.9999995'')', week('0000-1-1 23:59:59.9999995')); +insert into test values('week(''0000-12-31 22:59:59.9999995'')', week('0000-12-31 22:59:59.9999995')); + +-- 双参数-功能 +insert into test values('week(''2000-1-1'', 0)', week('2000-1-1', 0)); +insert into test values('week(''2000-1-1'', 1)', week('2000-1-1', 1)); +insert into test values('week(''2000-1-1'', 2)', week('2000-1-1', 2)); +insert into test values('week(''2000-1-1'', 3)', week('2000-1-1', 3)); +insert into test values('week(''2000-1-1'', 4)', week('2000-1-1', 4)); +insert into test values('week(''2000-1-1'', 5)', week('2000-1-1', 5)); +insert into test values('week(''2000-1-1'', 6)', week('2000-1-1', 6)); +insert into test values('week(''2000-1-1'', 7)', week('2000-1-1', 7)); +insert into test values('week(''0000-12-31 23:59:59.9999995'', 0)', week('0000-12-31 23:59:59.9999995', 0)); +-- 双参数-特异 +insert into test values('week(null, 0)', week(null, 0)); +insert into test values('week(''2000-1-1'', null)', week('2000-1-1', null)); +insert into test values('week(null, null)', week(null, null)); + +-- 双参数-非严格模式,参数不合法,报warning,返回NULL或者对应值 +set dolphin.sql_mode = 'sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('week(''10000-1-1'', 0)', week('10000-1-1', 0)); +insert into test values('week(''9999-12-31 23:59:59.9999995'', 0)', week('9999-12-31 23:59:59.9999995', 0)); +insert into test values('week(0, 0)', week(0, 0)); +insert into test values('week(-1, 0)', week(-1, 0)); +insert into test values('week(100000101, 0)', week(100000101, 0)); +insert into test values('week(99991231235959.9999995, 0)', week(99991231235959.9999995, 0)); +insert into test values('week(9999999999999999999999, 0)', week(9999999999999999999999, 0)); +insert into test values('week(''0000-1-1 23:59:59.9999995'', 0)', week('0000-1-1 23:59:59.9999995', 0)); +insert into test values('week(''0000-12-31 22:59:59.9999995'', 0)', week('0000-12-31 22:59:59.9999995', 0)); + +-- 双参数-严格模式,参数不合法,抛出错误 +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('week(''10000-1-1'', 0)', week('10000-1-1', 0)); +insert into test values('week(''9999-12-31 23:59:59.9999995'', 0)', week('9999-12-31 23:59:59.9999995', 0)); +insert into test values('week(0, 0)', week(0, 0)); +insert into test values('week(-1, 0)', week(-1, 0)); +insert into test values('week(100000101, 0)', week(100000101, 0)); +insert into test values('week(99991231235959.9999995, 0)', week(99991231235959.9999995, 0)); +insert into test values('week(9999999999999999999999, 0)', week(9999999999999999999999, 0)); +insert into test values('week(''0000-1-1 23:59:59.9999995'', 0)', week('0000-1-1 23:59:59.9999995', 0)); +insert into test values('week(''0000-12-31 22:59:59.9999995'', 0)', week('0000-12-31 22:59:59.9999995', 0)); + +--test yearweek +-- 严格模式或者非严格模式都有值 +-- 单参数-功能 +insert into test values('yearweek(''2000-1-1'')', yearweek('2000-1-1')); +insert into test values('yearweek(''0000-12-31 23:59:59.9999995'')', yearweek('0000-12-31 23:59:59.9999995')); +-- 单参数-边界 +insert into test values('yearweek(''0000-1-1'')', yearweek('0000-1-1')); +insert into test values('yearweek(''9999-12-31'')', yearweek('9999-12-31')); +insert into test values('yearweek(''0000-1-1 00:00:00'')', yearweek('0000-1-1 00:00:00')); +insert into test values('yearweek(''9999-12-31 23:59:59.999999'')', yearweek('9999-12-31 23:59:59.999999')); +-- 单参数-类型 +insert into test values('yearweek(date''0000-1-1'')', yearweek(date'0000-1-1')); +insert into test values('yearweek(cast(''9999-12-31 12:12:12'' as datetime))', yearweek(cast('9999-12-31 12:12:12' as datetime))); +insert into test values('yearweek(101)', yearweek(101)); +insert into test values('yearweek(99991231)', yearweek(99991231)); +insert into test values('yearweek(99991231235959.999999)', yearweek(99991231235959.999999)); +insert into test values('yearweek(20211112235959.999999)', yearweek(20211112235959.999999)); +insert into test values('yearweek(20211112235959.9999999)', yearweek(20211112235959.9999999)); +-- 单参数-特异 +insert into test values('yearweek(null)', yearweek(null)); + +-- 单参数-非严格模式,参数不合法,报warning,返回NULL或者对应值 +set dolphin.sql_mode = 'sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('yearweek(''10000-1-1'')', yearweek('10000-1-1')); +insert into test values('yearweek(''9999-12-31 23:59:59.9999995'')', yearweek('9999-12-31 23:59:59.9999995')); +insert into test values('yearweek(0)', yearweek(0)); +insert into test values('yearweek(-1)', yearweek(-1)); +insert into test values('yearweek(100000101)', yearweek(100000101)); +insert into test values('yearweek(99991231235959.9999995)', yearweek(99991231235959.9999995)); +insert into test values('yearweek(9999999999999999999999)', yearweek(9999999999999999999999)); +insert into test values('yearweek(''0000-1-1 23:59:59.9999995'')', yearweek('0000-1-1 23:59:59.9999995')); +insert into test values('yearweek(''0000-12-31 22:59:59.9999995'')', yearweek('0000-12-31 22:59:59.9999995')); + +-- 单参数-严格模式,参数不合法,抛出错误 +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('yearweek(''10000-1-1'')', yearweek('10000-1-1')); +insert into test values('yearweek(''9999-12-31 23:59:59.9999995'')', yearweek('9999-12-31 23:59:59.9999995')); +insert into test values('yearweek(0)', yearweek(0)); +insert into test values('yearweek(-1)', yearweek(-1)); +insert into test values('yearweek(100000101)', yearweek(100000101)); +insert into test values('yearweek(99991231235959.9999995)', yearweek(99991231235959.9999995)); +insert into test values('yearweek(9999999999999999999999)', yearweek(9999999999999999999999)); +insert into test values('yearweek(''0000-1-1 23:59:59.9999995'')', yearweek('0000-1-1 23:59:59.9999995')); +insert into test values('yearweek(''0000-12-31 22:59:59.9999995'')', yearweek('0000-12-31 22:59:59.9999995')); + +-- 双参数-功能 +insert into test values('yearweek(''2000-1-1'', 0)', yearweek('2000-1-1', 0)); +insert into test values('yearweek(''2000-1-1'', 1)', yearweek('2000-1-1', 1)); +insert into test values('yearweek(''2000-1-1'', 2)', yearweek('2000-1-1', 2)); +insert into test values('yearweek(''2000-1-1'', 3)', yearweek('2000-1-1', 3)); +insert into test values('yearweek(''2000-1-1'', 4)', yearweek('2000-1-1', 4)); +insert into test values('yearweek(''2000-1-1'', 5)', yearweek('2000-1-1', 5)); +insert into test values('yearweek(''2000-1-1'', 6)', yearweek('2000-1-1', 6)); +insert into test values('yearweek(''2000-1-1'', 7)', yearweek('2000-1-1', 7)); +insert into test values('yearweek(''0000-12-31 23:59:59.9999995'', 0)', yearweek('0000-12-31 23:59:59.9999995', 0)); +-- 双参数-特异 +insert into test values('yearweek(null, 0)', yearweek(null, 0)); +insert into test values('yearweek(''2000-1-1'', null)', yearweek('2000-1-1', null)); +insert into test values('yearweek(null, null)', yearweek(null, null)); + +-- 双参数-非严格模式,参数不合法,报warning,返回NULL或者对应值 +set dolphin.sql_mode = 'sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('yearweek(''10000-1-1'', 0)', yearweek('10000-1-1', 0)); +insert into test values('yearweek(''9999-12-31 23:59:59.9999995'', 0)', yearweek('9999-12-31 23:59:59.9999995', 0)); +insert into test values('yearweek(0, 0)', yearweek(0, 0)); +insert into test values('yearweek(-1, 0)', yearweek(-1, 0)); +insert into test values('yearweek(100000101, 0)', yearweek(100000101, 0)); +insert into test values('yearweek(99991231235959.9999995, 0)', yearweek(99991231235959.9999995, 0)); +insert into test values('yearweek(9999999999999999999999, 0)', yearweek(9999999999999999999999, 0)); +insert into test values('yearweek(''0000-1-1 23:59:59.9999995'', 0)', yearweek('0000-1-1 23:59:59.9999995', 0)); +insert into test values('yearweek(''0000-12-31 22:59:59.9999995'', 0)', yearweek('0000-12-31 22:59:59.9999995', 0)); + +-- 双参数-严格模式,参数不合法,抛出错误 +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('yearweek(''10000-1-1'', 0)', yearweek('10000-1-1', 0)); +insert into test values('yearweek(''9999-12-31 23:59:59.9999995'', 0)', yearweek('9999-12-31 23:59:59.9999995', 0)); +insert into test values('yearweek(0, 0)', yearweek(0, 0)); +insert into test values('yearweek(-1, 0)', yearweek(-1, 0)); +insert into test values('yearweek(100000101, 0)', yearweek(100000101, 0)); +insert into test values('yearweek(99991231235959.9999995, 0)', yearweek(99991231235959.9999995, 0)); +insert into test values('yearweek(9999999999999999999999, 0)', yearweek(9999999999999999999999, 0)); +insert into test values('yearweek(''0000-1-1 23:59:59.9999995'', 0)', yearweek('0000-1-1 23:59:59.9999995', 0)); +insert into test values('yearweek(''0000-12-31 22:59:59.9999995'', 0)', yearweek('0000-12-31 22:59:59.9999995', 0)); + +-- 结果 +select * from test order by funcname; +drop table test; +\c contrib_regression +DROP DATABASE b_datetime_func_test2; \ No newline at end of file diff --git "a/Data_governance/\346\265\213\350\257\225\347\233\270\345\205\263/\346\265\213\350\257\225\347\224\250\344\276\213/db_b_date_time_functions3.sql" "b/Data_governance/\346\265\213\350\257\225\347\233\270\345\205\263/\346\265\213\350\257\225\347\224\250\344\276\213/db_b_date_time_functions3.sql" new file mode 100644 index 0000000000000000000000000000000000000000..e22065f0cf4952354d5b448ad86f2b307e145bba --- /dev/null +++ "b/Data_governance/\346\265\213\350\257\225\347\233\270\345\205\263/\346\265\213\350\257\225\347\224\250\344\276\213/db_b_date_time_functions3.sql" @@ -0,0 +1,503 @@ +---- b compatibility case +drop database if exists b_datetime_func_test3; +create database b_datetime_func_test3 encoding 'UTF-8' lc_collate 'C' lc_ctype 'C' dbcompatibility 'B'; +\c b_datetime_func_test3 +set datestyle = 'ISO,ymd'; +set time zone "Asia/Shanghai"; +create table test(funcname text, result text); +-- test datediff +-- 严格模式或者非严格模式都有值 +-- 功能 +insert into test values('datediff(''2021-11-12'', ''2021-11-13'')', datediff('2021-11-12','2021-11-13')); +insert into test values('datediff(''2021-01-01'', ''2021-12-31'')', datediff('2021-01-01','2021-12-31')); +insert into test values('datediff(''2021-12-31'', ''2022-01-01'')', datediff('2021-12-31','2022-01-01')); +insert into test values('datediff(''2021-12-31 12:12:12'', ''2022-01-01 10:10:10'')', datediff('2021-12-31 12:12:12','2022-01-01 10:10:10')); +-- 边界 +insert into test values('datediff(''0000-01-01'', ''9999-12-31'')', datediff('0000-01-01', '9999-12-31')); +insert into test values('datediff(''9999-12-31'', ''0000-01-01'')', datediff('9999-12-31', '0000-01-01')); +-- 类型 +insert into test values('datediff(date''2021-11-12'', date''2021-11-13'')', datediff(date'2021-11-13', date'2021-11-13')); +insert into test values('datediff(cast(''2021-12-31 12:12:12'' as datetime), cast(''2022-01-01 10:10:10'' as datetime))', datediff(cast('2021-12-31 12:12:12' as datetime), cast('2022-01-01 10:10:10' as datetime))); +insert into test values('datediff(20211112, 20211113)', datediff(20211112, 20211113)); +insert into test values('datediff(time''10:10:10'', ''2022-11-30'')', datediff(time'10:10:10', '2022-11-30')); +insert into test values('datediff(''2022-11-30'', time''10:10:10'')', datediff('2022-11-30', time'10:10:10')); +insert into test values('datediff(time''10:10:10'', time''10:10:10'')', datediff(time'10:10:10', time'10:10:10')); +insert into test values('datediff(101, ''2021-11-12'')', datediff(101, '2021-11-12')); +insert into test values('datediff(''2021-11-12'', 101)', datediff('2021-11-12', 101)); +insert into test values('datediff(''2021-11-12'', 101)', datediff('2021-11-12', 101)); +-- 特异 +insert into test values('datediff(null, ''2021-11-12'')', datediff(null, '2021-11-12')); +insert into test values('datediff(''2021-11-12'', null)', datediff('2021-11-12', null)); +insert into test values('datediff(null, null)', datediff(null, null)); + +-- 非严格模式,参数不合法,报warning,返回NULL或者对应值 +set dolphin.sql_mode = 'sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('datediff(''10000-01-01'', ''2021-11-12'')', datediff('10000-01-01', '2021-11-12')); +insert into test values('datediff(100000101, 20211112)', datediff(100000101, 20211112)); +insert into test values('datediff(99991231235959.9999995, 20211112)', datediff(99991231235959.9999995, 20211112)); +insert into test values('datediff(9999999999999999999999, 20211112)', datediff(9999999999999999999999, 20211112)); + +-- 严格模式,参数不合法,抛出错误 +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('datediff(''10000-01-01'', ''2021-11-12'')', datediff('10000-01-01', '2021-11-12')); +insert into test values('datediff(100000101, 20211112)', datediff(100000101, 20211112)); +insert into test values('datediff(99991231235959.9999995, 20211112)', datediff(99991231235959.9999995, 20211112)); +insert into test values('datediff(9999999999999999999999, 20211112)', datediff(9999999999999999999999, 20211112)); + +-- test from_days +-- 严格模式或者非严格模式都有值 +-- 功能 +insert into test values('from_days(2000000)', from_days(2000000)); +insert into test values('from_days(''2000000'')', from_days('2000000')); +-- 边界 +insert into test values('from_days(366)', from_days(366)); +insert into test values('from_days(3652499)', from_days(3652499)); +insert into test values('from_days(''366'')', from_days('366')); +insert into test values('from_days(''3652499'')', from_days('3652499')); +-- 特异 +insert into test values('from_days(null)', from_days(null)); +insert into test values('from_days(-1)', from_days(-1)); +insert into test values('from_days(0)', from_days(0)); +insert into test values('from_days(365)', from_days(365)); +insert into test values('from_days(1111111111111111111)', from_days(1111111111111111111)); +insert into test values('from_days(''1111111111111111111'')', from_days('1111111111111111111')); + +-- test timestampdiff +set dolphin.b_compatibility_mode = true; +-- 严格模式或者非严格模式都有值 +-- 功能 +insert into test values('timestampdiff(microsecond, ''0000-1-1 00:00:00'', ''0000-1-2'')', timestampdiff(microsecond, '0000-1-1 00:00:00', '0000-1-2')); +insert into test values('timestampdiff(second, ''0000-1-1 00:00:00'', ''0000-1-2'')', timestampdiff(second, '0000-1-1 00:00:00', '0000-1-2')); +insert into test values('timestampdiff(minute, ''0000-1-1 00:00:00'', ''0000-1-2'')', timestampdiff(minute, '0000-1-1 00:00:00', '0000-1-2')); +insert into test values('timestampdiff(hour, ''0000-1-1'', ''0000-1-2'')', timestampdiff(hour, '0000-1-1', '0000-1-2')); +insert into test values('timestampdiff(year, ''9999-12-31'', ''0000-12-31'')', timestampdiff(year, '9999-12-31', '0000-12-31')); +insert into test values('timestampdiff(quarter, ''9999-12-31'', ''0000-12-31'')', timestampdiff(quarter, '9999-12-31', '0000-12-31')); +insert into test values('timestampdiff(month, ''9999-12-31'', ''0000-12-31'')', timestampdiff(month, '9999-12-31', '0000-12-31')); +insert into test values('timestampdiff(week, ''9999-12-31'', ''0000-12-31'')', timestampdiff(week, '9999-12-31', '0000-12-31')); +insert into test values('timestampdiff(day, ''9999-12-31'', ''0000-12-31'')', timestampdiff(day, '9999-12-31', '0000-12-31')); +insert into test values('timestampdiff(microsecond, time''-838:59:59'', time''838:59:59'')', timestampdiff(microsecond, time'-838:59:59', time'838:59:59')); +insert into test values('timestampdiff(second, time''-838:59:59'', time''838:59:59'')', timestampdiff(second, time'-838:59:59', time'838:59:59')); +insert into test values('timestampdiff(minute, time''-838:59:59'', time''838:59:59'')', timestampdiff(minute, time'-838:59:59', time'838:59:59')); +insert into test values('timestampdiff(hour, time''-838:59:59'', time''838:59:59'')', timestampdiff(hour, time'-838:59:59', time'838:59:59')); +insert into test values('timestampdiff(day, time''-838:59:59'', time''838:59:59'')', timestampdiff(day, time'-838:59:59', time'838:59:59')); +insert into test values('timestampdiff(month, time''-838:59:59'', time''838:59:59'')', timestampdiff(month, time'-838:59:59', time'838:59:59')); +insert into test values('timestampdiff(quarter, time''-838:59:59'', time''838:59:59'')', timestampdiff(quarter, time'-838:59:59', time'838:59:59')); +insert into test values('timestampdiff(year, time''-838:59:59'', time''838:59:59'')', timestampdiff(year, time'-838:59:59', time'838:59:59')); +insert into test values('timestampdiff(week, time''-838:59:59'', time''838:59:59'')', timestampdiff(week, time'-838:59:59', time'838:59:59')); +insert into test values('timestampdiff(microsecond, ''2022-9-12'', time''12:12:12'')', timestampdiff(microsecond, '2022-9-12', time'12:12:12')); +insert into test values('timestampdiff(microsecond, time''12:12:12'', ''2022-9-12'')', timestampdiff(microsecond, time'12:12:12', '2022-9-12')); +insert into test values('timestampdiff(microsecond, ''2022-9-12 12:12:12'', time''838:59:59'')', timestampdiff(microsecond, '2022-9-12 12:12:12', time'838:59:59')); +-- 边界 +insert into test values('timestampdiff(microsecond, ''0000-1-1'', ''9999-12-31'')', timestampdiff(microsecond, '0000-1-1', '9999-12-31')); +insert into test values('timestampdiff(second, ''0000-1-1'', ''9999-12-31'')', timestampdiff(second, '0000-1-1', '9999-12-31')); +insert into test values('timestampdiff(minute, ''0000-1-1'', ''9999-12-31'')', timestampdiff(minute, '0000-1-1', '9999-12-31')); +insert into test values('timestampdiff(hour, ''0000-1-1'', ''9999-12-31'')', timestampdiff(hour, '9999-12-31', '0000-12-31')); +insert into test values('timestampdiff(day, ''0000-1-1'', ''9999-12-31'')', timestampdiff(day, '0000-1-1', '9999-12-31')); +insert into test values('timestampdiff(year, ''0000-1-1'', ''9999-12-31'')', timestampdiff(year, '0000-1-1', '9999-12-31')); +insert into test values('timestampdiff(quarter, ''0000-1-1'', ''9999-12-31'')', timestampdiff(quarter, '0000-1-1', '9999-12-31')); +insert into test values('timestampdiff(month, ''0000-1-1'', ''9999-12-31'')', timestampdiff(month, '0000-1-1', '9999-12-31')); +insert into test values('timestampdiff(week, ''0000-1-1'', ''9999-12-31'')', timestampdiff(week, '0000-1-1', '9999-12-31')); +-- 类型 +insert into test values('timestampdiff(microsecond, cast(''2022-9-12 12:12:12.999999'' as datetime), time''12:12:12.999999'')', timestampdiff(microsecond, cast('2022-9-12 12:12:12.999999' as datetime), time'12:12:12.999999')); +insert into test values('timestampdiff(microsecond, time''12:12:12.999999'', cast(''2022-9-12 12:12:12.999999'' as datetime))', timestampdiff(microsecond, time'12:12:12.999999', cast('2022-9-12 12:12:12.999999' as datetime))); +insert into test values('timestampdiff(microsecond, date''2022-9-12'', time''12:12:12.999999'')',timestampdiff(microsecond, date'2022-9-12', time'12:12:12.999999')); +insert into test values('timestampdiff(microsecond, time''12:12:12.999999'', date''2022-9-12'')', timestampdiff(microsecond, time'12:12:12.999999', date'2022-9-12')); +insert into test values('timestampdiff(microsecond, ''20211112121212.999999'', ''20220912111111.999999'')', timestampdiff(microsecond, '20211112121212.999999', '20220912111111.999999')); +insert into test values('timestampdiff(microsecond, 101, ''20211112121212.999999'')', timestampdiff(microsecond, 101, '20211112121212.999999')); +insert into test values('timestampdiff(microsecond, ''20211112121212.999999'', 101)', timestampdiff(microsecond, '20211112121212.999999', 101)); +insert into test values('timestampdiff(microsecond, 99991231235959.999999, 101)', timestampdiff(microsecond, 99991231235959.999999, 101)); +insert into test values('timestampdiff(microsecond, 101, 99991231235959.999999)', timestampdiff(microsecond, 101, 99991231235959.999999)); +-- 特异 +insert into test values('timestampdiff(week, null, ''9999-12-31'')', timestampdiff(week, null, '9999-12-31')); +insert into test values('timestampdiff(week, ''9999-12-31'', null)', timestampdiff(week, '9999-12-31', null)); +insert into test values('timestampdiff(week, null, null)', timestampdiff(week, null, null)); + +-- 非严格模式,参数不合法,报warning,返回NULL或者对应值 +set dolphin.sql_mode = 'sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('timestampdiff(microsecond, ''abc'', ''2021-11-12'')', timestampdiff(microsecond, 'abc', '2021-11-12')); +insert into test values('timestampdiff(microsecond, ''2021-11-12'', ''10000-1-1'')', timestampdiff(microsecond, '2021-11-12', '10000-1-1')); +insert into test values('timestampdiff(microsecond, ''10000-1-1'', ''2021-11-12'')', timestampdiff(microsecond, '10000-1-1', '2021-11-12')); + +-- 严格模式,参数不合法,抛出错误 +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('timestampdiff(microsecond, ''abc'', ''2021-11-12'')', timestampdiff(microsecond, 'abc', '2021-11-12')); +insert into test values('timestampdiff(microsecond, ''2021-11-12'', ''10000-1-1'')', timestampdiff(microsecond, '2021-11-12', '10000-1-1')); +insert into test values('timestampdiff(microsecond, ''10000-1-1'', ''2021-11-12'')', timestampdiff(microsecond, '10000-1-1', '2021-11-12')); +set dolphin.b_compatibility_mode = false; + +-- test convert_tz +-- 严格模式或者非严格模式都有值 +-- 双字母,第一次转换超[1970-1-1 00:00:01.000000, 2038-01-19 03:14:07.999999],结果不转换 +insert into test values('convert_tz(''1970-1-1 00:00:01.000000'', ''MET'', ''GMT'')', convert_tz('1970-1-1 00:00:01.000000', 'MET', 'GMT')); +insert into test values('convert_tz(''1970-1-1 00:00:01.000000'', ''CCT'', ''GMT'')', convert_tz('1970-1-1 00:00:01.000000', 'CCT', 'GMT')); +insert into test values('convert_tz(''2038-01-19 03:14:07.999999'', ''EDT'', ''GMT'')', convert_tz('2038-01-19 03:14:07.999999', 'EDT', 'GMT')); +-- 双字母正常转换 +insert into test values('convert_tz(''1234-1-1 00:00:00'', ''MET'', ''GMT'')', convert_tz('1234-1-1 00:00:00', 'MET', 'GMT')); +insert into test values('convert_tz(''1970-1-1 00:00:01.000000'', ''GMT'', ''GMT'')', convert_tz('1970-1-1 00:00:01.000000', 'GMT', 'GMT')); +insert into test values('convert_tz(''1970-1-1 00:00:01.000000'', ''EDT'', ''GMT'')', convert_tz('1970-1-1 00:00:01.000000', 'EDT', 'GMT')); +insert into test values('convert_tz(''1970-1-1 00:00:01.000000'', ''CDT'', ''GMT'')', convert_tz('1970-1-1 00:00:01.000000', 'CDT', 'GMT')); +insert into test values('convert_tz(''1970-1-1 00:00:01.000000'', ''EST'', ''GMT'')', convert_tz('1970-1-1 00:00:01.000000', 'EST', 'GMT')); +insert into test values('convert_tz(''1970-1-1 00:00:01.000000'', ''MDT'', ''GMT'')', convert_tz('1970-1-1 00:00:01.000000', 'MDT', 'GMT')); +insert into test values('convert_tz(''1970-1-1 00:00:01.000000'', ''MST'', ''GMT'')', convert_tz('1970-1-1 00:00:01.000000', 'MST', 'GMT')); +insert into test values('convert_tz(''2038-01-19 03:14:07.999999'', ''JST'', ''GMT'')',convert_tz('2038-01-19 03:14:07.999999', 'JST', 'GMT')); +insert into test values('convert_tz(''2038-01-19 03:14:07.999999'', ''KST'', ''GMT'')',convert_tz('2038-01-19 03:14:07.999999', 'KST', 'GMT')); +insert into test values('convert_tz(''2038-01-19 03:14:07.999999'', ''CCT'', ''GMT'')',convert_tz('2038-01-19 03:14:07.999999', 'CCT', 'GMT')); +-- 双数字,第一次转换超[1970-1-1 00:00:01.000000, 2038-01-19 03:14:07.999999],结果不转换 +insert into test values('convert_tz(''1970-1-1 00:00:01.000000'', ''+1:00'', ''+0:00'')', convert_tz('1970-1-1 00:00:01.000000', '+1:00', '+0:00')); +insert into test values('convert_tz(''2038-01-19 03:14:07.999999'', ''-1:00'', ''+0:00'')', convert_tz('1970-1-1 00:00:01.000000', '+1:00', '+0:00')); +-- 双数字正常转换 +insert into test values('convert_tz(''1970-1-1 00:00:01.000000'', ''-1:00'', ''+0:00'')', convert_tz('1970-1-1 00:00:01.000000', '-1:00', '+0:00')); +insert into test values('convert_tz(''1970-1-1 00:00:01.000000'', ''-2:00'', ''+0:00'')', convert_tz('1970-1-1 00:00:01.000000', '-2:00', '+0:00')); +insert into test values('convert_tz(''1970-1-1 00:00:01.000000'', ''-10:00'', ''+0:00'')', convert_tz('1970-1-1 00:00:01.000000', '-10:00', '+0:00')); +insert into test values('convert_tz(''2038-01-19 03:14:07.999999'', ''+1:00'', ''+0:00'')', convert_tz('2038-01-19 03:14:07.999999', '+1:00', '+0:00')); +insert into test values('convert_tz(''2038-01-19 03:14:07.999999'', ''+2:00'', ''+0:00'')', convert_tz('2038-01-19 03:14:07.999999', '+2:00', '+0:00')); +insert into test values('convert_tz(''2038-01-19 03:14:07.999999'', ''+10:00'', ''+0:00'')', convert_tz('2038-01-19 03:14:07.999999', '+10:00', '+0:00')); +-- 字母数字混合 +insert into test values('convert_tz(''1970-1-1 00:00:01.000000'', ''-1:00'', ''GMT'')', convert_tz('1970-1-1 00:00:01.000000', '-1:00', 'GMT')); +insert into test values('convert_tz(''1970-1-1 00:00:01.000000'', ''GMT'', ''+3:00'')', convert_tz('1970-1-1 00:00:01.000000', 'GMT', '+3:00')); +insert into test values('convert_tz(''2038-01-19 03:14:07.999999'', ''+2:00'', ''GMT'')', convert_tz('2038-01-19 03:14:07.999999', '+2:00', 'GMT')); +insert into test values('convert_tz(''2038-01-19 03:14:07.999999'', ''GMT'', ''+7:00'')', convert_tz('2038-01-19 03:14:07.999999', 'GMT', '+7:00')); +insert into test values('convert_tz(time''10:10:10'', ''GMT'', ''+7:00'')', convert_tz(time'10:10:10', 'GMT', '+7:00')); +insert into test values('convert_tz(101, ''GMT'', ''+7:00'')', convert_tz(101, 'GMT', '+7:00')); +-- 特异 +insert into test values('convert_tz(null, ''+1:00'', ''+0:00'')', convert_tz(null, '+1:00', '+0:00')); +insert into test values('convert_tz(''2021-11-12 12:12:12'', null, ''+0:00'')', convert_tz('2021-11-12 12:12:12', null, '+0:00')); +insert into test values('convert_tz(''2021-11-12 12:12:12'', ''+1:00'', null)', convert_tz('2021-11-12 12:12:12', '+1:00', null)); +insert into test values('convert_tz(''2021-11-12 12:12:12'', ''abc'', ''+0:00'')', convert_tz('2021-11-12 12:12:12', 'abc', '+0:00')); +insert into test values('convert_tz(''2021-11-12 12:12:12'', ''+1:00'', ''abc'')', convert_tz('2021-11-12 12:12:12', '+1:00', 'abc')); +insert into test values('convert_tz(''2021-11-12 12:12:12'', ''+13:01'', ''+0:00'')', convert_tz('2021-11-12 12:12:12', '+13:01', '+0:00')); +insert into test values('convert_tz(''2021-11-12 12:12:12'', ''+0:00'', ''-13:00'')', convert_tz('2021-11-12 12:12:12', '+0:00', '-13:00')); +-- 非严格模式,参数不合法,报warning,返回NULL或者对应值 +set dolphin.sql_mode = 'sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('convert_tz(''10000-1-1 10:10:10'', ''+1:00'', ''+0:00'')', convert_tz('10000-1-1 10:10:10', '+1:00', '+0:00')); + +-- 严格模式,参数不合法,抛出错误 +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('convert_tz(''10000-1-1 10:10:10'', ''+1:00'', ''+0:00'')', convert_tz('10000-1-1 10:10:10', '+1:00', '+0:00')); + + +-- test adddate(date/datetime/time, INTERVAL/days) +-- 严格模式或者非严格模式都有值 +-- 功能-unit +insert into test values('adddate(''0001-01-01'',INTERVAL 1 year)', adddate('0001-01-01',INTERVAL 1 year)); +insert into test values('adddate(''0001-01-01'',INTERVAL 1 day)', adddate('0001-01-01',INTERVAL 1 day)); +insert into test values('adddate(''0001-01-01'',INTERVAL 1 month)', adddate('0001-01-01',INTERVAL 1 month)); +insert into test values('adddate(''0001-01-01'',INTERVAL 1 hour)', adddate('0001-01-01',INTERVAL 1 hour)); +insert into test values('adddate(''0001-01-01'',INTERVAL 1 minute)', adddate('0001-01-01',INTERVAL 1 minute)); +insert into test values('adddate(''0001-01-01'',INTERVAL 1 second)', adddate('0001-01-01',INTERVAL 1 second)); +insert into test values('adddate(''0001-01-01 12:12:12'',INTERVAL 1 hour)', adddate('0001-01-01 12:12:12',INTERVAL 1 hour)); +insert into test values('adddate(''0001-01-01 12:12:12'',INTERVAL 1 minute)', adddate('0001-01-01 12:12:12',INTERVAL 1 minute)); +insert into test values('adddate(''0001-01-01 12:12:12'',INTERVAL 1 second)', adddate('0001-01-01 12:12:12',INTERVAL 1 second)); +insert into test values('adddate(''9999-12-31'',INTERVAL -1 year)', adddate('9999-12-31',INTERVAL -1 year)); +insert into test values('adddate(''9999-12-31'',INTERVAL -1 day)', adddate('9999-12-31',INTERVAL -1 day)); +insert into test values('adddate(''9999-12-31'',INTERVAL -1 month)', adddate('9999-12-31',INTERVAL -1 month)); +insert into test values('adddate(''9999-12-31'',INTERVAL -1 hour)', adddate('9999-12-31',INTERVAL -1 hour)); +insert into test values('adddate(''9999-12-31'',INTERVAL -1 minute)', adddate('9999-12-31',INTERVAL -1 minute)); +insert into test values('adddate(''9999-12-31'',INTERVAL -1 second)', adddate('9999-12-31',INTERVAL -1 second)); +insert into test values('adddate(''9999-12-31 12:12:12'',INTERVAL -1 hour)', adddate('9999-12-31 12:12:12',INTERVAL -1 hour)); +insert into test values('adddate(''9999-12-31 12:12:12'',INTERVAL -1 minute)', adddate('9999-12-31 12:12:12',INTERVAL -1 minute)); +insert into test values('adddate(''9999-12-31 12:12:12'',INTERVAL -1 second)', adddate('9999-12-31 12:12:12',INTERVAL -1 second)); +insert into test values('adddate(''2021-11-12'', -1)', adddate('2021-11-12', -1)); +insert into test values('adddate(''2021-11-12'', 1)', adddate('2021-11-12', 1)); +insert into test values('adddate(''11:11:11'', 2)', adddate('11:11:11', 2)); +insert into test values('adddate(''11:11:11'', INTERVAL 2 day)', adddate('11:11:11', INTERVAL 2 day)); +insert into test values('adddate(''11:11:11'', INTERVAL 2 second)', adddate('11:11:11', INTERVAL 2 second)); +-- 功能-一些进位情况 +insert into test values('adddate(''0001-12-31'',INTERVAL 1 day)',adddate('0001-12-31',INTERVAL 1 day)); +insert into test values('adddate(''2021-12-31'',INTERVAL 1 day)',adddate('2021-12-31',INTERVAL 1 day)); +insert into test values('adddate(''9998-12-31'',INTERVAL 1 day)',adddate('9998-12-31',INTERVAL 1 day)); +insert into test values('adddate(''0001-12-31'',INTERVAL 1 month)',adddate('0001-12-31',INTERVAL 1 month)); +insert into test values('adddate(''1999-12-31'',INTERVAL 1 day)',adddate('1999-12-31',INTERVAL 1 day)); +insert into test values('adddate(''1999-12-31'',INTERVAL 1 year)',adddate('1999-12-31',INTERVAL 1 year)); +insert into test values('adddate(''1999-12-31 23:59:59'',INTERVAL 1 second)',adddate('1999-12-31 23:59:59',INTERVAL 1 second)); +insert into test values('adddate(''1999-12-31 23:59:00'',INTERVAL 1 minute)',adddate('1999-12-31 23:59:00',INTERVAL 1 minute)); +insert into test values('adddate(''1999-12-31 23:00:00'',INTERVAL 1 hour)',adddate('1999-12-31 23:00:00',INTERVAL 1 hour)); +-- 功能-第一参数为显示time类型 +insert into test values('adddate(time''12:12:12'', INTERVAL 1 day)', adddate(time'12:12:12', INTERVAL 1 day)); +insert into test values('adddate(time''12:12:12'', INTERVAL 1 hour)', adddate(time'12:12:12', INTERVAL 1 hour)); +insert into test values('adddate(time''12:12:12'', INTERVAL 1 minute)', adddate(time'12:12:12', INTERVAL 1 minute)); +insert into test values('adddate(time''12:12:12'', INTERVAL 1 second)', adddate(time'12:12:12', INTERVAL 1 second)); +insert into test values('adddate(time''12:12:12'', INTERVAL -1 day)', adddate(time'12:12:12', INTERVAL -1 day)); +insert into test values('adddate(time''12:12:12'', INTERVAL -1 hour)', adddate(time'12:12:12', INTERVAL -1 hour)); +insert into test values('adddate(time''12:12:12'', INTERVAL -1 minute)', adddate(time'12:12:12', INTERVAL -1 minute)); +insert into test values('adddate(time''12:12:12'', INTERVAL -1 second)', adddate(time'12:12:12', INTERVAL -1 second)); +insert into test values('adddate(time''12:12:12'', 1)', adddate(time'12:12:12', 1)); +insert into test values('adddate(time''12:12:12'', -1)', adddate(time'12:12:12', -1)); +-- 类型 +insert into test values('adddate(date''0001-01-01'',INTERVAL 1 year)', adddate(date'0001-01-01',INTERVAL 1 year)); +insert into test values('adddate(cast(''9999-12-31 12:12:12'' as datetime),INTERVAL -1 second)', adddate(cast('9999-12-31 12:12:12' as datetime), INTERVAL -1 second)); +insert into test values('adddate(time''838:59:59'', INTERVAL -1 second)', adddate(time'838:59:59',INTERVAL -1 second)); +insert into test values('adddate(101, INTERVAL 1 year)', adddate(101, INTERVAL 1 year)); +insert into test values('adddate(101, INTERVAL 100 second)', adddate(101, INTERVAL 100 second)); +insert into test values('adddate(101, 1)', adddate(101, 1)); +-- 特异 +insert into test values('adddate(null, INTERVAL 1 day)', adddate(null, INTERVAL 1 day)); +insert into test values('adddate(''2021-11-12'', null)', adddate('2021-11-12', null)); +insert into test values('adddate(null, null)', adddate(null, null)); + +-- 非严格模式,参数或者结果不合法,报warning,返回NULL或者对应值 +set dolphin.sql_mode = 'sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('adddate(0, INTERVAL 100 second)', adddate(0, INTERVAL 100 second)); +insert into test values('adddate(''10000-1-1'', INTERVAL -1 day)', adddate('10000-1-1', INTERVAL -1 day)); +insert into test values('adddate(''9999-12-31'', INTERVAL 1 day)', adddate('9999-12-31', INTERVAL 1 day)); +insert into test values('adddate(''9999-12-31'', INTERVAL 1 month)', adddate('9999-12-31', INTERVAL 1 month)); +insert into test values('adddate(''9999-12-31'', INTERVAL 1 year)', adddate('9999-12-31', INTERVAL 1 year)); +insert into test values('adddate(''9999-12-31 23:59:59'', INTERVAL 1 second)', adddate('9999-12-31 23:59:59', INTERVAL 1 second)); +insert into test values('adddate(''9999-12-31 23:59:00'', INTERVAL 1 minute)', adddate('9999-12-31 23:59:00', INTERVAL 1 minute)); +insert into test values('adddate(''9999-12-31 23:00:00'', INTERVAL 1 hour)', adddate('9999-12-31 23:00:00', INTERVAL 1 hour)); +insert into test values('adddate(time''838:59:59'', INTERVAL 1 second)', adddate(time'838:59:59', INTERVAL 1 second)); +insert into test values('adddate(time''-838:59:59'', INTERVAL -1 second)', adddate(time'-838:59:59', INTERVAL -1 second)); + +-- 严格模式,参数不合法,抛出错误 +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('adddate(0, INTERVAL 100 second)', adddate(0, INTERVAL 100 second)); +insert into test values('adddate(''10000-1-1'', INTERVAL -1 day)', adddate('10000-1-1', INTERVAL -1 day)); +insert into test values('adddate(''9999-12-31'', INTERVAL 1 day)', adddate('9999-12-31', INTERVAL 1 day)); +insert into test values('adddate(''9999-12-31'', INTERVAL 1 month)', adddate('9999-12-31', INTERVAL 1 month)); +insert into test values('adddate(''9999-12-31'', INTERVAL 1 year)', adddate('9999-12-31', INTERVAL 1 year)); +insert into test values('adddate(''9999-12-31 23:59:59'', INTERVAL 1 second)', adddate('9999-12-31 23:59:59', INTERVAL 1 second)); +insert into test values('adddate(''9999-12-31 23:59:00'', INTERVAL 1 minute)', adddate('9999-12-31 23:59:00', INTERVAL 1 minute)); +insert into test values('adddate(''9999-12-31 23:00:00'', INTERVAL 1 hour)', adddate('9999-12-31 23:00:00', INTERVAL 1 hour)); +insert into test values('adddate(time''838:59:59'', INTERVAL 1 second)', adddate(time'838:59:59', INTERVAL 1 second)); +insert into test values('adddate(time''-838:59:59'', INTERVAL -1 second)', adddate(time'-838:59:59', INTERVAL -1 second)); + +-- 结果小于'0001-1-1 00:00:00'时,结果中日期部分置为'0000-00-00',时间部分为相应值。 +insert into test values('adddate(''0001-1-1'', INTERVAL -1 day)', adddate('0001-1-1', INTERVAL -1 day)); +insert into test values('adddate(''0001-1-1'', -1)', adddate('0001-1-1', -1)); +insert into test values('adddate(''0001-1-1 00:00:00'', INTERVAL -1 second)', adddate('0001-1-1 00:00:00', INTERVAL -1 second)); + +-- 结果超越边界,严格模式报错,非严格模式报warning,返回NULL。 +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('adddate(''00010101'', -367)', adddate('00010101', -367)); +set dolphin.sql_mode = 'sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('adddate(''00010101'', -367)', adddate('00010101', -367)); + +-- test date_add(date/datetime/time, INTERVAL) +-- 严格模式或者非严格模式都有值 +-- 功能-unit +insert into test values('date_add(''0001-01-01'',INTERVAL 1 year)', date_add('0001-01-01',INTERVAL 1 year)); +insert into test values('date_add(''0001-01-01'',INTERVAL 1 day)', date_add('0001-01-01',INTERVAL 1 day)); +insert into test values('date_add(''0001-01-01'',INTERVAL 1 month)', date_add('0001-01-01',INTERVAL 1 month)); +insert into test values('date_add(''0001-01-01'',INTERVAL 1 hour)', date_add('0001-01-01',INTERVAL 1 hour)); +insert into test values('date_add(''0001-01-01'',INTERVAL 1 minute)', date_add('0001-01-01',INTERVAL 1 minute)); +insert into test values('date_add(''0001-01-01'',INTERVAL 1 second)', date_add('0001-01-01',INTERVAL 1 second)); +insert into test values('date_add(''0001-01-01 12:12:12'',INTERVAL 1 hour)', date_add('0001-01-01 12:12:12',INTERVAL 1 hour)); +insert into test values('date_add(''0001-01-01 12:12:12'',INTERVAL 1 minute)', date_add('0001-01-01 12:12:12',INTERVAL 1 minute)); +insert into test values('date_add(''0001-01-01 12:12:12'',INTERVAL 1 second)', date_add('0001-01-01 12:12:12',INTERVAL 1 second)); +insert into test values('date_add(''9999-12-31'',INTERVAL -1 year)', date_add('9999-12-31',INTERVAL -1 year)); +insert into test values('date_add(''9999-12-31'',INTERVAL -1 day)', date_add('9999-12-31',INTERVAL -1 day)); +insert into test values('date_add(''9999-12-31'',INTERVAL -1 month)', date_add('9999-12-31',INTERVAL -1 month)); +insert into test values('date_add(''9999-12-31'',INTERVAL -1 hour)', date_add('9999-12-31',INTERVAL -1 hour)); +insert into test values('date_add(''9999-12-31'',INTERVAL -1 minute)', date_add('9999-12-31',INTERVAL -1 minute)); +insert into test values('date_add(''9999-12-31'',INTERVAL -1 second)', date_add('9999-12-31',INTERVAL -1 second)); +insert into test values('date_add(''9999-12-31 12:12:12'',INTERVAL -1 hour)', date_add('9999-12-31 12:12:12',INTERVAL -1 hour)); +insert into test values('date_add(''9999-12-31 12:12:12'',INTERVAL -1 minute)', date_add('9999-12-31 12:12:12',INTERVAL -1 minute)); +insert into test values('date_add(''9999-12-31 12:12:12'',INTERVAL -1 second)', date_add('9999-12-31 12:12:12',INTERVAL -1 second)); +-- 功能-一些进位情况 +insert into test values('date_add(''0001-12-31'',INTERVAL 1 day)',date_add('0001-12-31',INTERVAL 1 day)); +insert into test values('date_add(''2021-12-31'',INTERVAL 1 day)',date_add('2021-12-31',INTERVAL 1 day)); +insert into test values('date_add(''9998-12-31'',INTERVAL 1 day)',date_add('9998-12-31',INTERVAL 1 day)); +insert into test values('date_add(''0001-12-31'',INTERVAL 1 month)',date_add('0001-12-31',INTERVAL 1 month)); +insert into test values('date_add(''1999-12-31'',INTERVAL 1 day)',date_add('1999-12-31',INTERVAL 1 day)); +insert into test values('date_add(''1999-12-31'',INTERVAL 1 year)',date_add('1999-12-31',INTERVAL 1 year)); +insert into test values('date_add(''1999-12-31 23:59:59'',INTERVAL 1 second)',date_add('1999-12-31 23:59:59',INTERVAL 1 second)); +insert into test values('date_add(''1999-12-31 23:59:00'',INTERVAL 1 minute)',date_add('1999-12-31 23:59:00',INTERVAL 1 minute)); +insert into test values('date_add(''1999-12-31 23:00:00'',INTERVAL 1 hour)',date_add('1999-12-31 23:00:00',INTERVAL 1 hour)); +-- 功能-第一参数为显示time类型 +insert into test values('date_add(time''12:12:12'', INTERVAL 1 day)', date_add(time'12:12:12', INTERVAL 1 day)); +insert into test values('date_add(time''12:12:12'', INTERVAL 1 hour)', date_add(time'12:12:12', INTERVAL 1 hour)); +insert into test values('date_add(time''12:12:12'', INTERVAL 1 minute)', date_add(time'12:12:12', INTERVAL 1 minute)); +insert into test values('date_add(time''12:12:12'', INTERVAL 1 second)', date_add(time'12:12:12', INTERVAL 1 second)); +insert into test values('date_add(time''12:12:12'', INTERVAL -1 day)', date_add(time'12:12:12', INTERVAL -1 day)); +insert into test values('date_add(time''12:12:12'', INTERVAL -1 hour)', date_add(time'12:12:12', INTERVAL -1 hour)); +insert into test values('date_add(time''12:12:12'', INTERVAL -1 minute)', date_add(time'12:12:12', INTERVAL -1 minute)); +insert into test values('date_add(time''12:12:12'', INTERVAL -1 second)', date_add(time'12:12:12', INTERVAL -1 second)); +-- 类型 +insert into test values('date_add(date''0001-01-01'',INTERVAL 1 year)', date_add(date'0001-01-01',INTERVAL 1 year)); +insert into test values('date_add(cast(''9999-12-31 12:12:12'' as datetime),INTERVAL -1 second)', date_add(cast('9999-12-31 12:12:12' as datetime), INTERVAL -1 second)); +insert into test values('date_add(time''838:59:59'', INTERVAL -1 second)', date_add(time'838:59:59',INTERVAL -1 second)); +insert into test values('date_add(101, INTERVAL 1 year)', date_add(101, INTERVAL 1 year)); +insert into test values('date_add(101, INTERVAL 100 second)', date_add(101, INTERVAL 100 second)); +-- 特异 +insert into test values('date_add(null, INTERVAL 1 day)', date_add(null, INTERVAL 1 day)); + +-- 非严格模式,参数或者结果不合法,报warning,返回NULL或者对应值 +set dolphin.sql_mode = 'sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('date_add(0, INTERVAL 100 second)', date_add(0, INTERVAL 100 second)); +insert into test values('date_add(''10000-1-1'', INTERVAL -1 day)', date_add('10000-1-1', INTERVAL -1 day)); +insert into test values('date_add(''9999-12-31'', INTERVAL 1 day)', date_add('9999-12-31', INTERVAL 1 day)); +insert into test values('date_add(''9999-12-31'', INTERVAL 1 month)', date_add('9999-12-31', INTERVAL 1 month)); +insert into test values('date_add(''9999-12-31'', INTERVAL 1 year)', date_add('9999-12-31', INTERVAL 1 year)); +insert into test values('date_add(''9999-12-31 23:59:59'', INTERVAL 1 second)', date_add('9999-12-31 23:59:59', INTERVAL 1 second)); +insert into test values('date_add(''9999-12-31 23:59:00'', INTERVAL 1 minute)', date_add('9999-12-31 23:59:00', INTERVAL 1 minute)); +insert into test values('date_add(''9999-12-31 23:00:00'', INTERVAL 1 hour)', date_add('9999-12-31 23:00:00', INTERVAL 1 hour)); +insert into test values('date_add(time''838:59:59'', INTERVAL 1 second)', date_add(time'838:59:59', INTERVAL 1 second)); +insert into test values('date_add(time''-838:59:59'', INTERVAL -1 second)', date_add(time'-838:59:59', INTERVAL -1 second)); + +-- 严格模式,参数不合法,抛出错误 +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('date_add(0, INTERVAL 100 second)', date_add(0, INTERVAL 100 second)); +insert into test values('date_add(''10000-1-1'', INTERVAL -1 day)', date_add('10000-1-1', INTERVAL -1 day)); +insert into test values('date_add(''9999-12-31'', INTERVAL 1 day)', date_add('9999-12-31', INTERVAL 1 day)); +insert into test values('date_add(''9999-12-31'', INTERVAL 1 month)', date_add('9999-12-31', INTERVAL 1 month)); +insert into test values('date_add(''9999-12-31'', INTERVAL 1 year)', date_add('9999-12-31', INTERVAL 1 year)); +insert into test values('date_add(''9999-12-31 23:59:59'', INTERVAL 1 second)', date_add('9999-12-31 23:59:59', INTERVAL 1 second)); +insert into test values('date_add(''9999-12-31 23:59:00'', INTERVAL 1 minute)', date_add('9999-12-31 23:59:00', INTERVAL 1 minute)); +insert into test values('date_add(''9999-12-31 23:00:00'', INTERVAL 1 hour)', date_add('9999-12-31 23:00:00', INTERVAL 1 hour)); +insert into test values('date_add(time''838:59:59'', INTERVAL 1 second)', date_add(time'838:59:59', INTERVAL 1 second)); +insert into test values('date_add(time''-838:59:59'', INTERVAL -1 second)', date_add(time'-838:59:59', INTERVAL -1 second)); + +-- 结果小于'0001-1-1 00:00:00'时,结果中日期部分置为'0000-00-00',时间部分为相应值。 +insert into test values('date_add(''0001-1-1'', INTERVAL -1 day)', date_add('0001-1-1', INTERVAL -1 day)); +insert into test values('date_add(''0001-1-1 00:00:00'', INTERVAL -1 second)', date_add('0001-1-1 00:00:00', INTERVAL -1 second)); + +-- 结果超越边界,严格模式报错,非严格模式报warning,返回NULL。 +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('date_add(''00010101'', INTERVAL -367 day)', date_add('00010101', INTERVAL -367 day)); +set dolphin.sql_mode = 'sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('date_add(''00010101'', INTERVAL -367 day)', date_add('00010101', INTERVAL -367 day)); + +-- test date_sub(date/datetime/time, INTERVAL) +-- 严格模式或者非严格模式都有值 +-- 功能-unit +insert into test values('date_sub(''0001-01-01'',INTERVAL -1 year)', date_sub('0001-01-01',INTERVAL -1 year)); +insert into test values('date_sub(''0001-01-01'',INTERVAL -1 day)', date_sub('0001-01-01',INTERVAL -1 day)); +insert into test values('date_sub(''0001-01-01'',INTERVAL -1 month)', date_sub('0001-01-01',INTERVAL -1 month)); +insert into test values('date_sub(''0001-01-01'',INTERVAL -1 hour)', date_sub('0001-01-01',INTERVAL -1 hour)); +insert into test values('date_sub(''0001-01-01'',INTERVAL -1 minute)', date_sub('0001-01-01',INTERVAL -1 minute)); +insert into test values('date_sub(''0001-01-01'',INTERVAL -1 second)', date_sub('0001-01-01',INTERVAL -1 second)); +insert into test values('date_sub(''0001-01-01 12:12:12'',INTERVAL -1 hour)', date_sub('0001-01-01 12:12:12',INTERVAL -1 hour)); +insert into test values('date_sub(''0001-01-01 12:12:12'',INTERVAL -1 minute)', date_sub('0001-01-01 12:12:12',INTERVAL -1 minute)); +insert into test values('date_sub(''0001-01-01 12:12:12'',INTERVAL -1 second)', date_sub('0001-01-01 12:12:12',INTERVAL -1 second)); +insert into test values('date_sub(''9999-12-31'',INTERVAL 1 year)', date_sub('9999-12-31',INTERVAL 1 year)); +insert into test values('date_sub(''9999-12-31'',INTERVAL 1 day)', date_sub('9999-12-31',INTERVAL 1 day)); +insert into test values('date_sub(''9999-12-31'',INTERVAL 1 month)', date_sub('9999-12-31',INTERVAL 1 month)); +insert into test values('date_sub(''9999-12-31'',INTERVAL 1 hour)', date_sub('9999-12-31',INTERVAL 1 hour)); +insert into test values('date_sub(''9999-12-31'',INTERVAL 1 minute)', date_sub('9999-12-31',INTERVAL 1 minute)); +insert into test values('date_sub(''9999-12-31'',INTERVAL 1 second)', date_sub('9999-12-31',INTERVAL 1 second)); +insert into test values('date_sub(''9999-12-31 12:12:12'',INTERVAL 1 hour)', date_sub('9999-12-31 12:12:12',INTERVAL 1 hour)); +insert into test values('date_sub(''9999-12-31 12:12:12'',INTERVAL 1 minute)', date_sub('9999-12-31 12:12:12',INTERVAL 1 minute)); +insert into test values('date_sub(''9999-12-31 12:12:12'',INTERVAL 1 second)', date_sub('9999-12-31 12:12:12',INTERVAL 1 second)); +-- 功能-一些进位情况 +insert into test values('date_sub(''0001-12-31'',INTERVAL -1 day)',date_sub('0001-12-31',INTERVAL -1 day)); +insert into test values('date_sub(''2021-12-31'',INTERVAL -1 day)',date_sub('2021-12-31',INTERVAL -1 day)); +insert into test values('date_sub(''9998-12-31'',INTERVAL -1 day)',date_sub('9998-12-31',INTERVAL -1 day)); +insert into test values('date_sub(''0001-12-31'',INTERVAL -1 month)',date_sub('0001-12-31',INTERVAL -1 month)); +insert into test values('date_sub(''1999-12-31'',INTERVAL -1 day)',date_sub('1999-12-31',INTERVAL -1 day)); +insert into test values('date_sub(''1999-12-31'',INTERVAL -1 year)',date_sub('1999-12-31',INTERVAL -1 year)); +insert into test values('date_sub(''1999-12-31 23:59:59'',INTERVAL -1 second)',date_sub('1999-12-31 23:59:59',INTERVAL -1 second)); +insert into test values('date_sub(''1999-12-31 23:59:00'',INTERVAL -1 minute)',date_sub('1999-12-31 23:59:00',INTERVAL -1 minute)); +insert into test values('date_sub(''1999-12-31 23:00:00'',INTERVAL -1 hour)',date_sub('1999-12-31 23:00:00',INTERVAL -1 hour)); +-- 功能-第一参数为显示time类型 +insert into test values('date_sub(time''12:12:12'', INTERVAL 1 day)', date_sub(time'12:12:12', INTERVAL 1 day)); +insert into test values('date_sub(time''12:12:12'', INTERVAL 1 hour)', date_sub(time'12:12:12', INTERVAL 1 hour)); +insert into test values('date_sub(time''12:12:12'', INTERVAL 1 minute)', date_sub(time'12:12:12', INTERVAL 1 minute)); +insert into test values('date_sub(time''12:12:12'', INTERVAL 1 second)', date_sub(time'12:12:12', INTERVAL 1 second)); +insert into test values('date_sub(time''12:12:12'', INTERVAL -1 day)', date_sub(time'12:12:12', INTERVAL -1 day)); +insert into test values('date_sub(time''12:12:12'', INTERVAL -1 hour)', date_sub(time'12:12:12', INTERVAL -1 hour)); +insert into test values('date_sub(time''12:12:12'', INTERVAL -1 minute)', date_sub(time'12:12:12', INTERVAL -1 minute)); +insert into test values('date_sub(time''12:12:12'', INTERVAL -1 second)', date_sub(time'12:12:12', INTERVAL -1 second)); +-- 类型 +insert into test values('date_sub(date''0001-01-01'',INTERVAL -1 year)', date_sub(date'0001-01-01',INTERVAL -1 year)); +insert into test values('date_sub(cast(''9999-12-31 12:12:12'' as datetime),INTERVAL -1 second)', date_sub(cast('9999-12-31 12:12:12' as datetime) ,INTERVAL -1 second)); +insert into test values('date_sub(time''838:59:59'', INTERVAL 1 second)', date_sub(time'838:59:59',INTERVAL 1 second)); +insert into test values('date_sub(101, INTERVAL 1 year)', date_sub(101, INTERVAL 1 year)); +insert into test values('date_sub(101, INTERVAL 100 second)', date_sub(101, INTERVAL 100 second)); +-- 特异 +insert into test values('date_sub(null, INTERVAL 1 day)', date_sub(null, INTERVAL 1 day)); + +-- 非严格模式,参数或者结果不合法,报warning,返回NULL或者对应值 +set dolphin.sql_mode = 'sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('date_sub(0, INTERVAL 100 second)', date_sub(0, INTERVAL 100 second)); +insert into test values('date_sub(''10000-1-1'', INTERVAL 1 day)', date_sub('10000-1-1', INTERVAL 1 day)); +insert into test values('date_sub(''9999-12-31'', INTERVAL -1 day)', date_sub('9999-12-31', INTERVAL -1 day)); +insert into test values('date_sub(''9999-12-31'', INTERVAL -1 month)', date_sub('9999-12-31', INTERVAL -1 month)); +insert into test values('date_sub(''9999-12-31'', INTERVAL -1 year)', date_sub('9999-12-31', INTERVAL -1 year)); +insert into test values('date_sub(''9999-12-31 23:59:59'', INTERVAL -1 second)', date_sub('9999-12-31 23:59:59', INTERVAL -1 second)); +insert into test values('date_sub(''9999-12-31 23:59:00'', INTERVAL -1 minute)', date_sub('9999-12-31 23:59:00', INTERVAL -1 minute)); +insert into test values('date_sub(''9999-12-31 23:00:00'', INTERVAL -1 hour)', date_sub('9999-12-31 23:00:00', INTERVAL -1 hour)); +insert into test values('date_sub(time''838:59:59'', INTERVAL -1 second)', date_sub(time'838:59:59', INTERVAL -1 second)); +insert into test values('date_sub(time''-838:59:59'', INTERVAL 1 second)', date_sub(time'-838:59:59', INTERVAL 1 second)); + +-- 严格模式,参数不合法,抛出错误 +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('date_sub(0, INTERVAL 100 second)', date_sub(0, INTERVAL 100 second)); +insert into test values('date_sub(''10000-1-1'', INTERVAL 1 day)', date_sub('10000-1-1', INTERVAL 1 day)); +insert into test values('date_sub(''9999-12-31'', INTERVAL -1 day)', date_sub('9999-12-31', INTERVAL -1 day)); +insert into test values('date_sub(''9999-12-31'', INTERVAL -1 month)', date_sub('9999-12-31', INTERVAL -1 month)); +insert into test values('date_sub(''9999-12-31'', INTERVAL -1 year)', date_sub('9999-12-31', INTERVAL -1 year)); +insert into test values('date_sub(''9999-12-31 23:59:59'', INTERVAL -1 second)', date_sub('9999-12-31 23:59:59', INTERVAL -1 second)); +insert into test values('date_sub(''9999-12-31 23:59:00'', INTERVAL -1 minute)', date_sub('9999-12-31 23:59:00', INTERVAL -1 minute)); +insert into test values('date_sub(''9999-12-31 23:00:00'', INTERVAL -1 hour)', date_sub('9999-12-31 23:00:00', INTERVAL -1 hour)); +insert into test values('date_sub(time''838:59:59'', INTERVAL -1 second)', date_sub(time'838:59:59', INTERVAL -1 second)); +insert into test values('date_sub(time''-838:59:59'', INTERVAL 1 second)', date_sub(time'-838:59:59', INTERVAL 1 second)); + +-- 结果小于'0001-1-1 00:00:00'时,结果中日期部分置为'0000-00-00',时间部分为相应值。 +insert into test values('date_sub(''0001-1-1'', INTERVAL 1 day)', date_sub('0001-1-1', INTERVAL 1 day)); +insert into test values('date_sub(''0001-1-1 00:00:00'', INTERVAL 1 second)', date_sub('0001-1-1 00:00:00', INTERVAL 1 second)); + +-- 结果超越边界,严格模式报错,非严格模式报warning,返回NULL。 +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('date_sub(''00010101'', INTERVAL -367 day)', date_sub('00010101', INTERVAL 367 day)); +set dolphin.sql_mode = 'sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('date_sub(''00010101'', INTERVAL -367 day)', date_sub('00010101', INTERVAL 367 day)); + +-- test addtime(datetime/time, time) +-- 严格模式或者非严格模式都有值 +-- 功能 +insert into test values('addtime(''00:00:00'', ''00:00:00'')', addtime('00:00:00', '00:00:00')); +insert into test values('addtime(''11:22:33'', ''20:20:20'')', addtime('11:22:33', '20:20:20')); +insert into test values('addtime(''11:22:33.999999'', ''00:00:00.000001'')', addtime('11:22:33.999999', '00:00:00.000001')); +insert into test values('addtime(''838:59:58'', ''00:00:01'')', addtime('838:59:58', '00:00:01')); +insert into test values('addtime(''838:59:59'', ''-00:00:01'')', addtime('838:59:59', '-00:00:01')); +insert into test values('addtime(''-838:59:58'', ''-00:00:01'')', addtime('-838:59:58', '-00:00:01')); +insert into test values('addtime(''-838:59:59'', ''00:00:01'')', addtime('-838:59:59', '00:00:01')); +insert into test values('addtime(''9999-12-31 23:59:59.999999'', ''00:00:00'')', addtime('9999-12-31 23:59:59.999999','00:00:00')); +insert into test values('addtime(''9999-12-31 23:59:59.999999'', ''-00:00:01'')', addtime('9999-12-31 23:59:59.999999','00:00:00')); +insert into test values('addtime(''9999-12-31 23:59:59.999999'', ''-838:59:59'')', addtime('9999-12-31 23:59:59.999999','-838:59:59')); +insert into test values('addtime(''2021-11-12 23:59:59'', ''23:59:10'')', addtime('2021-11-12 23:59:59', '23:59:10')); +insert into test values('addtime(''11:11:11'', ''11:11:11'')', addtime('11:11:11', '11:11:11')); +-- 类型 +insert into test values('addtime(cast(''9999-12-31 23:59:59.999999'' as datetime(6)), ''00:00:00'')', addtime(cast('9999-12-31 23:59:59.999999' as datetime(6)),'00:00:00')); +insert into test values('addtime(time''12:12:12.999999'', ''00:00:00.000001'')', addtime(time'12:12:12.999999', '00:00:00.000001')); +insert into test values('addtime(''-8385959'', ''00:00:01'')', addtime('-8385959', '00:00:01')); +insert into test values('addtime(-8385959, ''00:00:01'')', addtime(-8385959, '00:00:01')); +insert into test values('addtime(0, ''00:00:01'')', addtime(0, '00:00:01')); +insert into test values('addtime(121112, ''10:00:00'')', addtime(121112, '10:00:00')); +-- 特异 +insert into test values('addtime(null, ''00:00:01'')', addtime(null, '00:00:01')); +insert into test values('addtime(''00:00:01'', null)', addtime('00:00:01', null)); +insert into test values('addtime(null, null)', addtime(null, null)); +insert into test values('addtime(''12:12:12'', ''2021-11-12 12:12:12'')', addtime('12:12:12', '2021-11-12 12:12:12')); +insert into test values('addtime(''0001-1-1 00:00:00'', ''-00:00:01'')', addtime('0001-1-1 00:00:00', '-00:00:01')); + +-- 非严格模式,参数或者结果不合法,报warning,返回NULL或者对应值 +set dolphin.sql_mode = 'sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('addtime(''839:00:00'', ''00:00:00'')', addtime('839:00:00', '00:00:00')); +insert into test values('addtime(''838:59:59'', ''00:00:01'')', addtime('838:59:59', '00:00:01')); +insert into test values('addtime(''838:59:59.1'', ''00:00:00'')', addtime('838:59:59.1', '00:00:00')); +insert into test values('addtime(''-838:59:59.1'', ''00:00:00'')', addtime('-838:59:59.1', '00:00:00')); +insert into test values('addtime(''-839:00:00'', ''00:00:00'')', addtime('-839:00:00', '00:00:00')); +insert into test values('addtime(''-838:59:59'', ''-00:00:01'')', addtime('-838:59:59', '-00:00:01')); +insert into test values('addtime(''9999-12-31 23:59:59'', ''00:00:01'')', addtime('9999-12-31 23:59:59', '00:00:01')); +insert into test values('addtime(''10000-1-1 00:00:00'', ''00:00:00'')', addtime('10000-1-1 00:00:00', '00:00:00')); +insert into test values('addtime(''2022-01-01'', ''11:11:11'')', addtime('2022-01-01', '11:11:11')); +insert into test values('addtime(99991231, ''10:00:00'')', addtime(99991231, '10:00:00')); + +-- 严格模式,参数或结果不合法,抛出错误 +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('addtime(''839:00:00'', ''00:00:00'')', addtime('839:00:00', '00:00:00')); +insert into test values('addtime(''838:59:59'', ''00:00:01'')', addtime('838:59:59', '00:00:01')); +insert into test values('addtime(''838:59:59.1'', ''00:00:00'')', addtime('838:59:59.1', '00:00:00')); +insert into test values('addtime(''-838:59:59.1'', ''00:00:00'')', addtime('-838:59:59.1', '00:00:00')); +insert into test values('addtime(''-839:00:00'', ''00:00:00'')', addtime('-839:00:00', '00:00:00')); +insert into test values('addtime(''-838:59:59'', ''-00:00:01'')', addtime('-838:59:59', '-00:00:01')); +insert into test values('addtime(''9999-12-31 23:59:59'', ''00:00:01'')', addtime('9999-12-31 23:59:59', '00:00:01')); +insert into test values('addtime(''10000-1-1 00:00:00'', ''00:00:00'')', addtime('10000-1-1 00:00:00', '00:00:00')); +insert into test values('addtime(''2022-01-01'', ''11:11:11'')', addtime('2022-01-01', '11:11:11')); +insert into test values('addtime(99991231, ''10:00:00'')', addtime(99991231, '10:00:00')); + +select * from test order by funcname; +drop table test; +\c contrib_regression +DROP DATABASE b_datetime_func_test3; \ No newline at end of file diff --git "a/Data_governance/\346\265\213\350\257\225\347\233\270\345\205\263/\346\265\213\350\257\225\347\224\250\344\276\213/db_b_date_time_functions4.sql" "b/Data_governance/\346\265\213\350\257\225\347\233\270\345\205\263/\346\265\213\350\257\225\347\224\250\344\276\213/db_b_date_time_functions4.sql" new file mode 100644 index 0000000000000000000000000000000000000000..6f7682602f79e23b75a83dd1b0a5d26c6a9511d6 --- /dev/null +++ "b/Data_governance/\346\265\213\350\257\225\347\233\270\345\205\263/\346\265\213\350\257\225\347\224\250\344\276\213/db_b_date_time_functions4.sql" @@ -0,0 +1,414 @@ +create schema b_datetime_func_test4; +set current_schema to 'b_datetime_func_test4'; +set datestyle = 'ISO,ymd'; +set time zone "Asia/Shanghai"; +create table test(funcname text, result text); +-- test get_format +-- 功能 +insert into test values('get_format(DATE, ''EUR'')', get_format(DATE, 'EUR')); +insert into test values('get_format(DATE, ''USA'')', get_format(DATE, 'USA')); +insert into test values('get_format(DATE, ''JIS'')', get_format(DATE, 'JIS')); +insert into test values('get_format(DATE, ''ISO'')', get_format(DATE, 'ISO')); +insert into test values('get_format(DATE, ''INTERNAL'')', get_format(DATE, 'INTERNAL')); +insert into test values('get_format(DATETIME, ''EUR'')', get_format(DATETIME, 'EUR')); +insert into test values('get_format(DATETIME, ''USA'')', get_format(DATETIME, 'USA')); +insert into test values('get_format(DATETIME, ''JIS'')', get_format(DATETIME, 'JIS')); +insert into test values('get_format(DATETIME, ''ISO'')', get_format(DATETIME, 'ISO')); +insert into test values('get_format(DATETIME, ''INTERNAL'')', get_format(DATETIME, 'INTERNAL')); +insert into test values('get_format(TIME, ''EUR'')', get_format(TIME, 'EUR')); +insert into test values('get_format(TIME, ''USA'')', get_format(TIME, 'USA')); +insert into test values('get_format(TIME, ''JIS'')', get_format(TIME, 'JIS')); +insert into test values('get_format(TIME, ''ISO'')', get_format(TIME, 'ISO')); +insert into test values('get_format(TIME, ''INTERNAL'')', get_format(TIME, 'INTERNAL')); +insert into test values('get_format(TIMESTAMP, ''EUR'')', get_format(TIMESTAMP, 'EUR')); +insert into test values('get_format(TIMESTAMP, ''USA'')', get_format(TIMESTAMP, 'USA')); +insert into test values('get_format(TIMESTAMP, ''JIS'')', get_format(TIMESTAMP, 'JIS')); +insert into test values('get_format(TIMESTAMP, ''ISO'')', get_format(TIMESTAMP, 'ISO')); +insert into test values('get_format(TIMESTAMP, ''INTERNAL'')', get_format(TIMESTAMP, 'INTERNAL')); +-- 特异 +insert into test values('get_format(DATE, ''abc'')', get_format(DATE, 'abc')); +insert into test values('get_format(DATE, null)', get_format(DATE, null)); +-- 错误情况 +insert into test values('get_format(abc, ''EUR'')', get_format(abc, 'EUR')); + +-- test extract +set dolphin.b_compatibility_mode = true; +-- 严格模式或者非严格模式都有值 +-- 功能-单unit +insert into test values('extract(YEAR FROM ''2019-07-02'')',extract(YEAR FROM '2019-07-02')); +insert into test values('extract(MONTH FROM ''2019-07-02'')',extract(MONTH FROM '2019-07-02')); +insert into test values('extract(WEEK FROM ''2019-07-02'')',extract(WEEK FROM '2019-07-02')); +insert into test values('extract(QUARTER FROM ''2019-07-02'')',extract(QUARTER FROM '2019-07-02')); +insert into test values('extract(DAY FROM ''2019-07-02'')',extract(DAY FROM '2019-07-02')); +insert into test values('extract(SECOND FROM ''2019-07-02 12:12:12'')',extract(SECOND FROM '2019-07-02 12:12:12')); +insert into test values('extract(MINUTE FROM ''2019-07-02 12:12:12'')',extract(MINUTE FROM '2019-07-02 12:12:12')); +insert into test values('extract(HOUR FROM ''2019-07-02 12:12:12'')',extract(HOUR FROM '2019-07-02 12:12:12')); +insert into test values('extract(MICROSECOND FROM ''2019-07-02 12:12:12.12121'')',extract(MICROSECOND FROM '2019-07-02 12:12:12.12121')); +insert into test values('extract(SECOND FROM ''12:12:12'')',extract(SECOND FROM '12:12:12')); +insert into test values('extract(MINUTE FROM ''12:12:12'')',extract(MINUTE FROM '12:12:12')); +insert into test values('extract(HOUR FROM ''12:12:12'')',extract(HOUR FROM '12:12:12')); +insert into test values('extract(MICROSECOND FROM ''12:12:12.12121'')',extract(MICROSECOND FROM '12:12:12.12121')); +-- 功能-混合unit +insert into test values('extract(YEAR_MONTH FROM ''2019-07-02'')',extract(YEAR_MONTH FROM '2019-07-02')); +insert into test values('extract(DAY_HOUR FROM ''2019-07-02 12:12:12'')', extract(DAY_HOUR FROM '2019-07-02 12:12:12')); +insert into test values('extract(DAY_MINUTE FROM ''2019-07-02 12:12:12'')', extract(DAY_MINUTE FROM '2019-07-02 12:12:12')); +insert into test values('extract(DAY_MICROSECOND FROM ''2019-07-02 12:12:12.12121'')', extract(DAY_MICROSECOND FROM '2019-07-02 12:12:12.12121')); +insert into test values('extract(SECOND_MICROSECOND FROM ''2019-07-02 12:12:12.12121'')', extract(SECOND_MICROSECOND FROM '2019-07-02 12:12:12.12121')); +insert into test values('extract(SECOND_MICROSECOND FROM ''12:12:12.12121'')', extract(SECOND_MICROSECOND FROM '12:12:12.12121')); +insert into test values('extract(MINUTE_MICROSECOND FROM ''2019-07-02 12:12:12.12121'')', extract(MINUTE_MICROSECOND FROM '2019-07-02 12:12:12.12121')); +insert into test values('extract(MINUTE_MICROSECOND FROM ''12:12:12.12121'')', extract(MINUTE_MICROSECOND FROM '12:12:12.12121')); +insert into test values('extract(MINUTE_SECOND FROM ''2019-07-02 12:12:12.12121'')', extract(MINUTE_SECOND FROM '2019-07-02 12:12:12.12121')); +insert into test values('extract(MINUTE_SECOND FROM ''12:12:12.12121'')', extract(MINUTE_SECOND FROM '12:12:12.12121')); +insert into test values('extract(HOUR_SECOND FROM ''2019-07-02 12:12:12.12121'')', extract(HOUR_SECOND FROM '2019-07-02 12:12:12.12121')); +insert into test values('extract(HOUR_SECOND FROM ''12:12:12.12121'')', extract(HOUR_SECOND FROM '12:12:12.12121')); +insert into test values('extract(HOUR_MINUTE FROM ''2019-07-02 12:12:12.12121'')', extract(HOUR_MINUTE FROM '2019-07-02 12:12:12.12121')); +insert into test values('extract(HOUR_MINUTE FROM ''12:12:12.12121'')', extract(HOUR_MINUTE FROM '12:12:12.12121')); +insert into test values('extract(HOUR_MICROSECOND FROM ''2019-07-02 12:12:12.12121'')', extract(HOUR_MICROSECOND FROM '2019-07-02 12:12:12.12121')); +insert into test values('extract(HOUR_MICROSECOND FROM ''12:12:12.12121'')', extract(HOUR_MICROSECOND FROM '12:12:12.12121')); +insert into test values('extract(day_hour from ''838:59:59'')',extract(day_hour from '838:59:59')); +insert into test values('extract(day_minute from ''838:59:59'')',extract(day_minute from '838:59:59')); +insert into test values('extract(day_second from ''838:59:59'')',extract(day_second from '838:59:59')); +insert into test values('extract(day_microsecond from ''838:59:59'')',extract(day_microsecond from '838:59:59')); +-- 边界 +insert into test values('extract(YEAR FROM ''9999-12-31'')', extract(YEAR FROM '9999-12-31')); +insert into test values('extract(YEAR FROM ''0000-1-1'')', extract(YEAR FROM '0000-1-1')); +insert into test values('extract(hour from ''838:59:59'')', extract(hour from '838:59:59')); +insert into test values('extract(hour from ''-838:59:59'')', extract(hour from '-838:59:59')); +-- 类型 +insert into test values('extract(hour from time''-838:59:59'')', extract(hour from time'-838:59:59')); +insert into test values('extract(MONTH FROM date''2019-07-02'')', extract(MONTH FROM date'2019-07-02')); +insert into test values('extract(YEAR from cast(''2019-07-02'' as datetime)', extract(YEAR from cast('2019-07-02' as datetime))); +insert into test values('extract(hour from 8385959)', extract(hour from 8385959)); +insert into test values('extract(MONTH FROM 20190702)', extract(MONTH FROM 20190702)); +insert into test values('extract(year FROM 101)', extract(year FROM 101)); +insert into test values('extract(month FROM 101)', extract(month FROM 101)); +insert into test values('extract(quarter FROM 101)', extract(quarter FROM 101)); +insert into test values('extract(day FROM 101)', extract(day FROM 101)); +insert into test values('extract(day_hour FROM 101)', extract(day_hour FROM 101)); +insert into test values('extract(day_microsecond FROM 101)', extract(day_microsecond FROM 101)); +insert into test values('extract(hour FROM 101)', extract(hour FROM 101)); +insert into test values('extract(minute FROM 101)', extract(minute FROM 101)); +insert into test values('extract(second FROM 101)', extract(second FROM 101)); +insert into test values('extract(microsecond FROM 101)', extract(microsecond FROM 101)); +insert into test values('extract(year FROM 0)', extract(year FROM 0)); +insert into test values('extract(month FROM 0)', extract(month FROM 0)); +insert into test values('extract(quarter FROM 0)', extract(quarter FROM 0)); +insert into test values('extract(day FROM 0)', extract(day FROM 0)); +insert into test values('extract(day_hour FROM 0)', extract(day_hour FROM 0)); +insert into test values('extract(day_microsecond FROM 0)', extract(day_microsecond FROM 0)); +insert into test values('extract(hour FROM 0)', extract(hour FROM 0)); +insert into test values('extract(minute FROM 0)', extract(minute FROM 0)); +insert into test values('extract(second FROM 0)', extract(second FROM 0)); +insert into test values('extract(microsecond FROM 0)', extract(microsecond FROM 0)); +insert into test values('extract(microsecond from 99991231235959.999999)', extract(microsecond from 99991231235959.999999)); +-- 特异 +insert into test values('extract(hour from null)', extract(hour from null)); +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('extract(YEAR FROM ''0000-00-00'')', extract(YEAR FROM '0000-00-00')); +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes'; +insert into test values('extract(YEAR FROM ''0000-00-00'')', extract(YEAR FROM '0000-00-00')); + +-- 非严格模式,参数不合法,报warning,返回NULL或者对应值 +set dolphin.sql_mode = 'sql_mode_full_group,pipes_as_concat,ansi_quotes'; +insert into test values('extract(DAY FROM ''10000-01-01'')', extract(DAY FROM '10000-01-01')); +insert into test values('extract(year from 100000101)', extract(year from 100000101)); +insert into test values('extract(hour from ''838:59:59.1'')', extract(hour from '838:59:59.1')); +insert into test values('extract(hour from ''839:00:00'')', extract(hour from '839:00:00')); +insert into test values('extract(hour from ''-838:59:59.1'')', extract(hour from '-838:59:59.1')); +insert into test values('extract(hour from ''-839:00:00'')', extract(hour from '-839:00:00')); +insert into test values('extract(hour from ''40 1:1:0'')', extract(hour from '40 1:1:0')); +insert into test values('extract(hour from ''-40 1:1:0'')', extract(hour from '-40 1:1:0')); +insert into test values('extract(day_hour from ''2022-01-01'')', extract(day_hour from '2022-01-01')); +insert into test values('extract(day_minute from ''2022-01-01'')', extract(day_minute from '2022-01-01')); +insert into test values('extract(day_second from ''2022-01-01'')', extract(day_second from '2022-01-01')); +insert into test values('extract(day_microsecond from ''2022-01-01'')', extract(day_microsecond from '2022-01-01')); +-- 严格模式,参数不合法,抛出错误 +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes'; +insert into test values('extract(DAY FROM ''10000-01-01'')', extract(DAY FROM '10000-01-01')); +insert into test values('extract(year from 100000101)', extract(year from 100000101)); +insert into test values('extract(hour from ''838:59:59.1'')', extract(hour from '838:59:59.1')); +insert into test values('extract(hour from ''839:00:00'')', extract(hour from '839:00:00')); +insert into test values('extract(hour from ''-838:59:59.1'')', extract(hour from '-838:59:59.1')); +insert into test values('extract(hour from ''-839:00:00'')', extract(hour from '-839:00:00')); +insert into test values('extract(hour from ''40 1:1:0'')', extract(hour from '40 1:1:0')); +insert into test values('extract(hour from ''-40 1:1:0'')', extract(hour from '-40 1:1:0')); +insert into test values('extract(day_hour from ''2022-01-01'')', extract(day_hour from '2022-01-01')); +insert into test values('extract(day_minute from ''2022-01-01'')', extract(day_minute from '2022-01-01')); +insert into test values('extract(day_second from ''2022-01-01'')', extract(day_second from '2022-01-01')); +insert into test values('extract(day_microsecond from ''2022-01-01'')', extract(day_microsecond from '2022-01-01')); +set dolphin.b_compatibility_mode = false; + +-- test date_format +-- 严格模式或者非严格模式都有值 +-- 功能 +insert into test values('date_format(''0000-01-01'',''%U %u %V %v %X %x %j'')', date_format('0000-01-01', '%U %u %V %v %X %x %j')); +insert into test values('date_format(''2021-11-12'',''%U %u %V %v %X %x %j'')', date_format('2021-11-12', '%U %u %V %v %X %x %j')); +insert into test values('date_format(''9999-12-31'',''%U %u %V %v %X %x %j'')', date_format('9999-12-31', '%U %u %V %v %X %x %j')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%a'')', date_format('2001-01-01 12:12:12','%a')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%b'')', date_format('2001-01-01 12:12:12','%b')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%c'')', date_format('2001-01-01 12:12:12','%c')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%D'')', date_format('2001-01-01 12:12:12','%D')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%d'')', date_format('2001-01-01 12:12:12','%d')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%e'')', date_format('2001-01-01 12:12:12','%e')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%f'')', date_format('2001-01-01 12:12:12','%f')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%H'')', date_format('2001-01-01 12:12:12','%H')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%h'')', date_format('2001-01-01 12:12:12','%h')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%I'')', date_format('2001-01-01 12:12:12','%I')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%i'')', date_format('2001-01-01 12:12:12','%i')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%j'')', date_format('2001-01-01 12:12:12','%j')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%k'')', date_format('2001-01-01 12:12:12','%k')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%l'')', date_format('2001-01-01 12:12:12','%l')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%M'')', date_format('2001-01-01 12:12:12','%M')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%m'')', date_format('2001-01-01 12:12:12','%m')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%p'')', date_format('2001-01-01 12:12:12','%p')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%r'')', date_format('2001-01-01 12:12:12','%r')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%S'')', date_format('2001-01-01 12:12:12','%S')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%s'')', date_format('2001-01-01 12:12:12','%s')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%T'')', date_format('2001-01-01 12:12:12','%T')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%U'')', date_format('2001-01-01 12:12:12','%U')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%u'')', date_format('2001-01-01 12:12:12','%u')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%V'')', date_format('2001-01-01 12:12:12','%V')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%v'')', date_format('2001-01-01 12:12:12','%v')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%W'')', date_format('2001-01-01 12:12:12','%W')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%w'')', date_format('2001-01-01 12:12:12','%w')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%X'')', date_format('2001-01-01 12:12:12','%X')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%x'')', date_format('2001-01-01 12:12:12','%x')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%Y'')', date_format('2001-01-01 12:12:12','%Y')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%y'')', date_format('2001-01-01 12:12:12','%y')); +insert into test values('date_format(''2001-01-01 12:12:12'',''aaaa'')', date_format('2001-01-01 12:12:12','aaaa')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%dffff'')', date_format('2001-01-01 12:12:12','%dffff')); +insert into test values('date_format(''2001-01-01 12:12:12.34567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'',''%b'')', date_format('2001-01-01 12:12:12.34567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890','%b')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b'')', date_format('2001-01-01 12:12:12','%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b%b')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%Y %M %D %U'')', date_format('2001-01-01 12:12:12','%Y %M %D %U')); +insert into test values('date_format(''2001-01-01 12:12:12'',''%H %k %I %r %T %S %w'')', date_format('2001-01-01 12:12:12','%H %k %I %r %T %S %w')); +-- 边界 +insert into test values('date_format(''0000-01-01'',''%Y'')', date_format('0000-01-01','%Y')); +insert into test values('date_format(''9999-12-31'',''%Y'')', date_format('9999-12-31','%Y')); +insert into test values('date_format(''0000-01-01 00:00:00'',''%Y %m %d %T'')', date_format('0000-01-01 00:00:00','%Y %m %d %T')); +insert into test values('date_format(''9999-12-31 23:59:59.999999'',''%Y %m %d %T %f'')', date_format('9999-12-31 23:59:59.999999','%Y %m %d %T %f')); +-- 类型 +insert into test values('date_format(date''2001-01-09'',''%Y'')', date_format(date'2001-01-09','%Y')); +insert into test values('date_format(cast(''2001-01-09 12:12:12'' as datetime),''%Y %m %d %T'')', date_format(cast('2001-01-09 12:12:12' as datetime),'%Y %m %d %T')); +insert into test values('date_format(20010101,''%Y'')', date_format(20010101,'%Y')); +insert into test values('date_format(20010101121212,''%Y %m %d %T'')', date_format(20010101121212,'%Y %m %d %T')); +insert into test values('date_format(20010101,''%Y'')', date_format(20010101,'%Y')); +insert into test values('date_format(101,''%Y %y %m %d %U %u %V %v %X %x'')', date_format(101,'%Y %y %m %d %U %u %V %v %X %x')); +-- 特异 +insert into test values('date_format(null, ''%Y'')', date_format(null, '%Y')); +insert into test values('date_format(''2021-11-12'', null)', date_format('2021-11-12', null)); +insert into test values('date_format(null, null)', date_format(null, null)); +insert into test values('date_format(''2021-0-12 12:12:12'', ''%Y %m %d %T'')', date_format('2021-0-12 12:12:12', '%Y %m %d %T')); +insert into test values('date_format(''2021-1-0 12:12:12'', ''%Y %m %d %T'')', date_format('2021-1-0 12:12:12', '%Y %m %d %T')); +insert into test values('date_format(''2021-0-0 12:12:12'', ''%Y %m %d %T'')', date_format('2021-0-0 12:12:12', '%Y %m %d %T')); +insert into test values('date_format(0, ''%Y %m %d'')', date_format(0, '%Y %m %d')); +set dolphin.sql_mode = 'sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('date_format(''0000-00-00'', ''%Y %m %d'')', date_format('0000-00-00', '%Y %m %d')); +set dolphin.sql_mode = 'sql_mode_full_group,pipes_as_concat,ansi_quotes'; +insert into test values('date_format(''0000-00-00'', ''%Y %m %d'')', date_format('0000-00-00', '%Y %m %d')); + +-- 非严格模式,参数不合法,报warning,返回NULL或者对应值 +set dolphin.sql_mode = 'sql_mode_full_group,pipes_as_concat,ansi_quotes'; +insert into test values('date_format(''10000-01-01 12:12:12'',''%Y %m %d %T'')', date_format('10000-01-01 12:12:12','%Y %m %d %T')); +insert into test values('date_format(''2001-01-32 12:12:12'',''%Y %m %d %T'')', date_format('2001-01-32 12:12:12','%Y %m %d %T')); +insert into test values('date_format(100000101, ''%b'')', date_format(100000101, '%b')); + +-- 严格模式,参数不合法,抛出错误 +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes'; +insert into test values('date_format(''10000-01-01 12:12:12'',''%Y %m %d %T'')', date_format('10000-01-01 12:12:12','%Y %m %d %T')); +insert into test values('date_format(''2001-01-32 12:12:12'',''%Y %m %d %T'')', date_format('2001-01-32 12:12:12','%Y %m %d %T')); +insert into test values('date_format(100000101, ''%b'')', date_format(100000101, '%b')); + +-- test from_unixtime +-- 严格模式或者非严格模式都有值 +-- 功能-单参数 +insert into test values('from_unixtime(0)', from_unixtime(0)); +insert into test values('from_unixtime(1)', from_unixtime(1)); +insert into test values('from_unixtime(1.999999)', from_unixtime(1.999999)); +insert into test values('from_unixtime(1.9999995)', from_unixtime(1.9999995)); +insert into test values('from_unixtime(1454545444)', from_unixtime(1454545444)); +-- 功能-双参数 +insert into test values('from_unixtime(0,''%Y-%m-%d %T'')', from_unixtime(0,'%Y-%m-%d %T')); +insert into test values('from_unixtime(1.999999,''%Y-%m-%d %T.%f'')', from_unixtime(1.999999,'%Y-%m-%d %T.%f')); +insert into test values('from_unixtime(1454545444,''%Y %M %D'')', from_unixtime(1454545444,'%Y %M %D')); +-- 边界 +insert into test values('from_unixtime(2147483647)', from_unixtime(2147483647)); +insert into test values('from_unixtime(2147483647,''%Y'')', from_unixtime(2147483647,'%Y')); + +-- 特异 +insert into test values('from_unixtime(null)', from_unixtime(null)); +insert into test values('from_unixtime(null,''%Y'')', from_unixtime(null,'%Y')); +insert into test values('from_unixtime(2147483647,null)', from_unixtime(2147483647,null)); +insert into test values('from_unixtime(null,null)', from_unixtime(null,null)); + +-- 超范围,空值 +insert into test values('from_unixtime(-1)', from_unixtime(-1)); +insert into test values('from_unixtime(-1454545444)', from_unixtime(-1454545444)); +insert into test values('from_unixtime(-1,''%Y'')', from_unixtime(-1,'%Y')); +insert into test values('from_unixtime(-1454545444,''%Y %M %D'')', from_unixtime(-1454545444,'%Y %M %D')); +insert into test values('from_unixtime(11111111111111111,''%Y %M %D'')', from_unixtime(11111111111111111,'%Y %M %D')); +insert into test values('from_unixtime(11111111111111111)', from_unixtime(11111111111111111)); +insert into test values('from_unixtime(2147483648)', from_unixtime(2147483648)); + +-- test str_to_date +-- 严格模式或者非严格模式都有值 +-- 功能-返回date +insert into test values('str_to_date(''2021-11-12'', ''%Y-%m-%d'')', str_to_date('2021-11-12', '%Y-%m-%d')); +insert into test values('str_to_date(''9999-12-31'', ''%Y-%m-%d'')', str_to_date('9999-12-31', '%Y-%m-%d')); +insert into test values('str_to_date(''12 12 12'', ''%y %m %d'')', str_to_date('12 12 12', '%y %m %d')); +insert into test values('str_to_date(''200442 Monday'', ''%X%V %W'')', str_to_date('200442 Monday', '%X%V %W')); +insert into test values('str_to_date(''200442 Monday'', ''%x%v %W'')', str_to_date('200442 Monday', '%x%v %W')); +insert into test values('str_to_date(''200442 Monday'', ''%Y%U %W'')', str_to_date('200442 Monday', '%Y%U %W')); +insert into test values('str_to_date(''200442 Monday'', ''%Y%u %W'')', str_to_date('200442 Monday', '%Y%u %W')); +insert into test values('str_to_date(''200442 Mon'', ''%Y%u %a'')', str_to_date('200442 Mon', '%Y%u %a')); +insert into test values('str_to_date(''200442 Tue'', ''%Y%u %a'')', str_to_date('200442 Tue', '%Y%u %a')); +insert into test values('str_to_date(''200442 Wed'', ''%Y%u %a'')', str_to_date('200442 Wed', '%Y%u %a')); +insert into test values('str_to_date(''200442 Thu'', ''%Y%u %a'')', str_to_date('200442 Thu', '%Y%u %a')); +insert into test values('str_to_date(''200442 Fri'', ''%Y%u %a'')', str_to_date('200442 Fri', '%Y%u %a')); +insert into test values('str_to_date(''200442 Sat'', ''%Y%u %a'')', str_to_date('200442 Sat', '%Y%u %a')); +insert into test values('str_to_date(''200442 Sun'', ''%Y%u %a'')', str_to_date('200442 Sun', '%Y%u %a')); +insert into test values('str_to_date(''200442 1'', ''%X%V %w'')', str_to_date('200442 1', '%X%V %w')); +insert into test values('str_to_date(''200442 1'', ''%x%v %w'')', str_to_date('200442 1', '%x%v %w')); +insert into test values('str_to_date(''200442 1'', ''%Y%U %w'')', str_to_date('200442 1', '%Y%U %w')); +insert into test values('str_to_date(''200442 1'', ''%Y%u %w'')', str_to_date('200442 1', '%Y%u %w')); +insert into test values('str_to_date(''200442 2'', ''%Y%u %w'')', str_to_date('200442 2', '%Y%u %w')); +insert into test values('str_to_date(''200442 3'', ''%Y%u %w'')', str_to_date('200442 3', '%Y%u %w')); +insert into test values('str_to_date(''200442 4'', ''%Y%u %w'')', str_to_date('200442 4', '%Y%u %w')); +insert into test values('str_to_date(''200442 5'', ''%Y%u %w'')', str_to_date('200442 5', '%Y%u %w')); +insert into test values('str_to_date(''200442 6'', ''%Y%u %w'')', str_to_date('200442 6', '%Y%u %w')); +insert into test values('str_to_date(''200442 0'', ''%Y%u %w'')', str_to_date('200442 0', '%Y%u %w')); +insert into test values('str_to_date(''2004 100'', ''%Y %j'')', str_to_date('2004 100', '%Y %j')); +insert into test values('str_to_date(''2004 January 12'', ''%Y %M %d'')', str_to_date('2004 January 12', '%Y %M %d')); +insert into test values('str_to_date(''2004 February 12'', ''%Y %M %d'')', str_to_date('2004 February 12', '%Y %M %d')); +insert into test values('str_to_date(''2004 March 12'', ''%Y %M %d'')', str_to_date('2004 March 12', '%Y %M %d')); +insert into test values('str_to_date(''2004 April 12'', ''%Y %M %d'')', str_to_date('2004 April 12', '%Y %M %d')); +insert into test values('str_to_date(''2004 May 12'', ''%Y %M %d'')', str_to_date('2004 May 12', '%Y %M %d')); +insert into test values('str_to_date(''2004 June 12'', ''%Y %M %d'')', str_to_date('2004 June 12', '%Y %M %d')); +insert into test values('str_to_date(''2004 July 12'', ''%Y %M %d'')', str_to_date('2004 July 12', '%Y %M %d')); +insert into test values('str_to_date(''2004 August 12'', ''%Y %M %d'')', str_to_date('2004 August 12', '%Y %M %d')); +insert into test values('str_to_date(''2004 September 12'', ''%Y %M %d'')', str_to_date('2004 September 12', '%Y %M %d')); +insert into test values('str_to_date(''2004 October 12'', ''%Y %M %d'')', str_to_date('2004 October 12', '%Y %M %d')); +insert into test values('str_to_date(''2004 November 12'', ''%Y %M %d'')', str_to_date('2004 November 12', '%Y %M %d')); +insert into test values('str_to_date(''2004 December 12'', ''%Y %M %d'')', str_to_date('2004 December 12', '%Y %M %d')); +insert into test values('str_to_date(''2004 Jan 12'', ''%Y %b %d'')', str_to_date('2004 Jan 12', '%Y %b %d')); +insert into test values('str_to_date(''2004 Feb 12'', ''%Y %b %d'')', str_to_date('2004 Feb 12', '%Y %b %d')); +insert into test values('str_to_date(''2004 Mar 12'', ''%Y %b %d'')', str_to_date('2004 Mar 12', '%Y %b %d')); +insert into test values('str_to_date(''2004 Apr 12'', ''%Y %b %d'')', str_to_date('2004 Apr 12', '%Y %b %d')); +insert into test values('str_to_date(''2004 May 12'', ''%Y %b %d'')', str_to_date('2004 May 12', '%Y %b %d')); +insert into test values('str_to_date(''2004 Jun 12'', ''%Y %b %d'')', str_to_date('2004 Jun 12', '%Y %b %d')); +insert into test values('str_to_date(''2004 Jul 12'', ''%Y %b %d'')', str_to_date('2004 Jul 12', '%Y %b %d')); +insert into test values('str_to_date(''2004 Aug 12'', ''%Y %b %d'')', str_to_date('2004 Aug 12', '%Y %b %d')); +insert into test values('str_to_date(''2004 Sep 12'', ''%Y %b %d'')', str_to_date('2004 Sep 12', '%Y %b %d')); +insert into test values('str_to_date(''2004 Oct 12'', ''%Y %b %d'')', str_to_date('2004 Oct 12', '%Y %b %d')); +insert into test values('str_to_date(''2004 Nov 12'', ''%Y %b %d'')', str_to_date('2004 Nov 12', '%Y %b %d')); +insert into test values('str_to_date(''2004 Dec 12'', ''%Y %b %d'')', str_to_date('2004 Dec 12', '%Y %b %d')); +-- 功能-返回datetime +insert into test values('str_to_date(''2021-11-12 12:12:12'', ''%Y-%m-%d %T'')', str_to_date('2021-11-12 12:12:12', '%Y-%m-%d %T')); +insert into test values('str_to_date(''9999-12-31 23:59:59'', ''%Y-%m-%d %T'')', str_to_date('9999-12-31 23:59:59', '%Y-%m-%d %T')); +insert into test values('str_to_date(''0000-1-1 00:00:00'', ''%Y-%m-%d %T'')', str_to_date('0000-1-1 00:00:00', '%Y-%m-%d %T')); +insert into test values('str_to_date(''2021-11-12 12:12:12.123456'', ''%Y-%m-%d %T.%f'')', str_to_date('2021-11-12 12:12:12.123456', '%Y-%m-%d %T.%f')); +insert into test values('str_to_date(''9999-12-31 23:59:59.999999'', ''%Y-%m-%d %T.%f'')', str_to_date('9999-12-31 23:59:59.999999', '%Y-%m-%d %T.%f')); +insert into test values('str_to_date(''0000-1-1 00:00:00.000000'', ''%Y-%m-%d %T.%f'')', str_to_date('0000-1-1 00:00:00.000000', '%Y-%m-%d %T.%f')); +-- 功能-返回time +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes'; +insert into test values('str_to_date(''0'', ''%H'')', str_to_date('0', '%H')); +insert into test values('str_to_date(''23'', ''%H'')', str_to_date('23', '%H')); +insert into test values('str_to_date(''12'', ''%h'')', str_to_date('12', '%h')); +insert into test values('str_to_date(''10:11:12'', ''%T'')', str_to_date('10:11:12', '%T')); +insert into test values('str_to_date(''10:11:12.999999'', ''%T.%f'')', str_to_date('10:11:12.999999', '%T.%f')); +insert into test values('str_to_date(''10:11:12'', ''%H:%i:%S'')', str_to_date('10:11:12', '%H:%i:%S')); +insert into test values('str_to_date(''10:11:12.999999'', ''%H:%i:%S.%f'')', str_to_date('10:11:12.999999', '%H:%i:%S.%f')); +insert into test values('str_to_date(''1:1:1 pm'', ''%r'')', str_to_date('1:1:1 pm', '%r')); +insert into test values('str_to_date(''1:1:1 am'', ''%r'')', str_to_date('1:1:1 am', '%r')); +insert into test values('str_to_date(''1:1:1 pm'', ''%h:%i:%S %p'')', str_to_date('1:1:1 pm', '%h:%i:%S %p')); +insert into test values('str_to_date(''1:1:1 am'', ''%h:%i:%S %p'')', str_to_date('1:1:1 am', '%h:%i:%S %p')); +insert into test values('str_to_date(''1:1:1.999999 pm'', ''%h:%i:%S.%f %p'')', str_to_date('1:1:1.999999 pm', '%h:%i:%S.%f %p')); +insert into test values('str_to_date(''1:1:1.999999 am'', ''%h:%i:%S.%f %p'')', str_to_date('1:1:1.999999 am', '%h:%i:%S.%f %p')); +-- 边界 +insert into test values('str_to_date(''0000 1 1'', ''%Y %m %d'')', str_to_date('0000 1 1', '%Y %m %d')); +insert into test values('str_to_date(''9999 12 31'', ''%Y %m %d'')', str_to_date('9999 12 31', '%Y %m %d')); +insert into test values('str_to_date(''0000 1 1 00:00:00'', ''%Y %m %d %T'')', str_to_date('0000 1 1 00:00:00', '%Y %m %d %T')); +insert into test values('str_to_date(''9999 12 31 23:59:59.999999'', ''%Y %m %d %T.%f'')', str_to_date('9999 12 31 23:59:59.999999', '%Y %m %d %T.%f')); +-- 特异 +insert into test values('str_to_date(null, ''%Y %m %d'')', str_to_date(null, '%Y %m %d')); +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes,no_zero_date'; +insert into test values('str_to_date(''0000-00-00'', ''%Y-%m-%d'')', str_to_date('0000-00-00', '%Y-%m-%d')); +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes'; +insert into test values('str_to_date(''0000-00-00'', ''%Y-%m-%d'')', str_to_date('0000-00-00', '%Y-%m-%d')); + +-- 非严格模式,参数不合法,报warning,返回NULL或者对应值 +set dolphin.sql_mode = 'sql_mode_full_group,pipes_as_concat,ansi_quotes'; +insert into test values('str_to_date(''0'', ''%h'')', str_to_date('0', '%h')); +insert into test values('str_to_date(''10000-1-1'', ''%Y-%m-%d'')', str_to_date('10000-1-1', '%Y-%m-%d')); +insert into test values('str_to_date(''2021-13-1'', ''%Y-%m-%d'')', str_to_date('2021-13-1', '%Y-%m-%d')); +insert into test values('str_to_date(''2021-1-32'', ''%Y-%m-%d'')', str_to_date('2021-1-32', '%Y-%m-%d')); +insert into test values('str_to_date(''2021-1-1 24:00:00'', ''%Y-%m-%d %T'')', str_to_date('2021-1-1 24:00:00', '%Y-%m-%d %T')); +insert into test values('str_to_date(''2021-1-1 00:60:00'', ''%Y-%m-%d %T'')', str_to_date('2021-1-1 00:60:00', '%Y-%m-%d %T')); +insert into test values('str_to_date(''2021-1-1 00:00:60'', ''%Y-%m-%d %T'')', str_to_date('2021-1-1 00:00:60', '%Y-%m-%d %T')); +insert into test values('str_to_date(''2021-1-1 24:00:00'', ''%Y-%m-%d %H:%i:%S'')', str_to_date('2021-1-1 24:00:00', '%Y-%m-%d %H:%i:%S')); +insert into test values('str_to_date(''2021-1-1 00:60:00'', ''%Y-%m-%d %H:%i:%S'')', str_to_date('2021-1-1 00:60:00', '%Y-%m-%d %H:%i:%S')); +insert into test values('str_to_date(''2021-1-1 00:00:60'', ''%Y-%m-%d %H:%i:%S'')', str_to_date('2021-1-1 00:00:60', '%Y-%m-%d %H:%i:%S')); +insert into test values('str_to_date(''13:00:00 pm'', ''%r'')', str_to_date('13:00:00 pm', '%r')); +insert into test values('str_to_date(''13:00:00 am'', ''%r'')', str_to_date('13:00:00 am', '%r')); +insert into test values('str_to_date(''24:00:00'', ''%T'')', str_to_date('24:00:00', '%T')); +insert into test values('str_to_date(''13:00:00'', ''%h:%i:%S'')', str_to_date('13:00:00', '%h:%i:%S')); +insert into test values('str_to_date(''24:00:00'', ''%H:%i:%S'')', str_to_date('24:00:00', '%H:%i:%S')); +insert into test values('str_to_date(''13'',''%h'')', str_to_date('13','%h')); +insert into test values('str_to_date(''24'',''%H'')', str_to_date('24','%H')); +insert into test values('str_to_date(''2021-11-12'', ''%Y/a%m/%d'')', str_to_date('2021-11-12', '%Y/a%m/%d')); +insert into test values('str_to_date(''2021-a11-12'', ''%Y/%m/%d'')', str_to_date('2021-a11-12', '%Y/%m/%d')); +insert into test values('str_to_date(''2021/11/12abc'', ''%Y/%m/%d'')', str_to_date('2021/11/12abc', '%Y/%m/%d')); +insert into test values('str_to_date(''200442 Monday'', ''%X%v %W'')', str_to_date('200442 Monday', '%X%v %W')); +insert into test values('str_to_date(''200442 Monday'', ''%x%V %W'')', str_to_date('200442 Monday', '%x%V %W')); +insert into test values('str_to_date(''200442 Monday'', ''%x%U %W'')', str_to_date('200442 Monday', '%x%U %W')); +insert into test values('str_to_date(''200442 Monday'', ''%x%u %W'')', str_to_date('200442 Monday', '%x%u %W')); +insert into test values('str_to_date(''200442 Monday'', ''%x%U %W'')', str_to_date('200442 Monday', '%x%U %W')); +insert into test values('str_to_date(''200442 Monday'', ''%x%u %W'')', str_to_date('200442 Monday', '%x%u %W')); +insert into test values('str_to_date(''2021-11-12'', null)', str_to_date('2021-11-12', null)); +insert into test values('str_to_date(''200454 Monday'', ''%X%V %W'')', str_to_date('200454 Monday', '%X%V %W')); + +-- 严格模式,参数不合法,抛出错误 +set dolphin.sql_mode = 'sql_mode_strict,sql_mode_full_group,pipes_as_concat,ansi_quotes'; +insert into test values('str_to_date(''0'', ''%h'')', str_to_date('0', '%h')); +insert into test values('str_to_date(''10000-1-1'', ''%Y-%m-%d'')', str_to_date('10000-1-1', '%Y-%m-%d')); +insert into test values('str_to_date(''2021-13-1'', ''%Y-%m-%d'')', str_to_date('2021-13-1', '%Y-%m-%d')); +insert into test values('str_to_date(''2021-1-32'', ''%Y-%m-%d'')', str_to_date('2021-1-32', '%Y-%m-%d')); +insert into test values('str_to_date(''2021-1-1 24:00:00'', ''%Y-%m-%d %T'')', str_to_date('2021-1-1 24:00:00', '%Y-%m-%d %T')); +insert into test values('str_to_date(''2021-1-1 00:60:00'', ''%Y-%m-%d %T'')', str_to_date('2021-1-1 00:60:00', '%Y-%m-%d %T')); +insert into test values('str_to_date(''2021-1-1 00:00:60'', ''%Y-%m-%d %T'')', str_to_date('2021-1-1 00:00:60', '%Y-%m-%d %T')); +insert into test values('str_to_date(''2021-1-1 24:00:00'', ''%Y-%m-%d %H:%i:%S'')', str_to_date('2021-1-1 24:00:00', '%Y-%m-%d %H:%i:%S')); +insert into test values('str_to_date(''2021-1-1 00:60:00'', ''%Y-%m-%d %H:%i:%S'')', str_to_date('2021-1-1 00:60:00', '%Y-%m-%d %H:%i:%S')); +insert into test values('str_to_date(''2021-1-1 00:00:60'', ''%Y-%m-%d %H:%i:%S'')', str_to_date('2021-1-1 00:00:60', '%Y-%m-%d %H:%i:%S')); +insert into test values('str_to_date(''13:00:00 pm'', ''%r'')', str_to_date('13:00:00 pm', '%r')); +insert into test values('str_to_date(''13:00:00 am'', ''%r'')', str_to_date('13:00:00 am', '%r')); +insert into test values('str_to_date(''24:00:00'', ''%T'')', str_to_date('24:00:00', '%T')); +insert into test values('str_to_date(''13:00:00'', ''%h:%i:%S'')', str_to_date('13:00:00', '%h:%i:%S')); +insert into test values('str_to_date(''24:00:00'', ''%H:%i:%S'')', str_to_date('24:00:00', '%H:%i:%S')); +insert into test values('str_to_date(''13'',''%h'')', str_to_date('13','%h')); +insert into test values('str_to_date(''24'',''%H'')', str_to_date('24','%H')); +insert into test values('str_to_date(''2021-11-12'', ''%Y/a%m/%d'')', str_to_date('2021-11-12', '%Y/a%m/%d')); +insert into test values('str_to_date(''2021-a11-12'', ''%Y/%m/%d'')', str_to_date('2021-a11-12', '%Y/%m/%d')); +insert into test values('str_to_date(''2021/11/12abc'', ''%Y/%m/%d'')', str_to_date('2021/11/12abc', '%Y/%m/%d')); +insert into test values('str_to_date(''200442 Monday'', ''%X%v %W'')', str_to_date('200442 Monday', '%X%v %W')); +insert into test values('str_to_date(''200442 Monday'', ''%x%V %W'')', str_to_date('200442 Monday', '%x%V %W')); +insert into test values('str_to_date(''200442 Monday'', ''%x%U %W'')', str_to_date('200442 Monday', '%x%U %W')); +insert into test values('str_to_date(''200442 Monday'', ''%x%u %W'')', str_to_date('200442 Monday', '%x%u %W')); +insert into test values('str_to_date(''200442 Monday'', ''%x%U %W'')', str_to_date('200442 Monday', '%x%U %W')); +insert into test values('str_to_date(''200442 Monday'', ''%x%u %W'')', str_to_date('200442 Monday', '%x%u %W')); +insert into test values('str_to_date(''2021-11-12'', null)', str_to_date('2021-11-12', null)); +insert into test values('str_to_date(''200454 Monday'', ''%X%V %W'')', str_to_date('200454 Monday', '%X%V %W')); + +-- 结果 +select * from test order by funcname; +drop table test; +-- fix bug +CREATE TABLE memos ( +ID integer, +CONTEXT text +); +insert into memos values(1,'2022/05/26 20:30'); +insert into memos values(2,'2022/05/27 20:30'); +select DATE_add(CONtext,INTERVAL 31 DAY) from memos; +drop table if exists memos; + +drop schema b_datetime_func_test4 cascade; +reset current_schema; diff --git "a/Data_governance/\346\265\213\350\257\225\347\233\270\345\205\263/\346\265\213\350\257\225\347\224\250\344\276\213/\347\254\254\344\270\200\351\230\266\346\256\265openGauss\346\211\247\350\241\214\347\273\223\346\236\234.docx" "b/Data_governance/\346\265\213\350\257\225\347\233\270\345\205\263/\346\265\213\350\257\225\347\224\250\344\276\213/\347\254\254\344\270\200\351\230\266\346\256\265openGauss\346\211\247\350\241\214\347\273\223\346\236\234.docx" new file mode 100644 index 0000000000000000000000000000000000000000..135efa24751b9b03b498ec8d768f5188cdfacdb0 Binary files /dev/null and "b/Data_governance/\346\265\213\350\257\225\347\233\270\345\205\263/\346\265\213\350\257\225\347\224\250\344\276\213/\347\254\254\344\270\200\351\230\266\346\256\265openGauss\346\211\247\350\241\214\347\273\223\346\236\234.docx" differ diff --git "a/Data_governance/\351\234\200\346\261\202\350\257\264\346\230\216\344\271\246/openGauss-\345\256\236\347\216\260\346\210\226\345\205\274\345\256\271MySQL\346\227\245\346\234\237\345\244\204\347\220\206\345\207\275\346\225\260\345\274\200\345\217\221\345\220\210\344\275\234\351\241\271\347\233\256.docx" "b/Data_governance/\351\234\200\346\261\202\350\257\264\346\230\216\344\271\246/openGauss-\345\256\236\347\216\260\346\210\226\345\205\274\345\256\271MySQL\346\227\245\346\234\237\345\244\204\347\220\206\345\207\275\346\225\260\345\274\200\345\217\221\345\220\210\344\275\234\351\241\271\347\233\256.docx" new file mode 100644 index 0000000000000000000000000000000000000000..9eb4e8e78b13eea695562b90f48d7e2c53caf4e7 Binary files /dev/null and "b/Data_governance/\351\234\200\346\261\202\350\257\264\346\230\216\344\271\246/openGauss-\345\256\236\347\216\260\346\210\226\345\205\274\345\256\271MySQL\346\227\245\346\234\237\345\244\204\347\220\206\345\207\275\346\225\260\345\274\200\345\217\221\345\220\210\344\275\234\351\241\271\347\233\256.docx" differ