-
Notifications
You must be signed in to change notification settings - Fork 364
[fix](doc) Fix date function second to timestamp #2816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ce5f7e0
to
1608949
Compare
函数将输入的 `TIME` 或 `DATETIME` 类型的值转换为以秒为单位的总时间。如果输入为 `DATETIME` 类型,函数会自动提取时间部分(`HH:MM:SS`)。 | ||
TIME_TO_SEC 函数用于将输入的时间值转换为以秒为单位的总秒数。该函数支持处理 TIME、DATETIME 类型:若输入为 DATETIME 类型,会自动提取其中的时间部分(HH:MM:SS)进行计算;若输入为纯时间值,则直接转换为总秒数。 | ||
|
||
该函数与 mysql 中的 [time_to_sec 函数](https://dev.mysql.com/doc/refman/8.4/en/date-and-time-functions.html#function_time-to-sec) 使用 SECOND 为单位的行为一致 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
“使用 SECOND 为单位的行为一致”多余的,看看还有没有别的复制粘贴出问题的
- 如果 `<end_datetime>` 或 `<start_datetime>` 为 `NULL`,函数返回 `NULL`。 | ||
- 如果 `<end_datetime>` 或 `<start_datetime>` 为非法时间或日期时间值(如 `0000-00-00 00:00:00`),函数返回 `NULL`。 | ||
- 当返回时间差不为整数秒时,返回时间带有 scale. | ||
- 当计算机结果超出 time 范围[-838:59:59,828:59:59],返回错误 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
计算结果。另外范围上界也不对吧
## 描述 | ||
|
||
TIMESTAMP 函数有两种用法: | ||
TIMESTAMP 将 datetime 字符串转换为 DATETIME 类型 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
符合datetime格式的字符串
| `string` | 日期时间字符串 | | ||
| `date` | 日期值,可以是 DATE 类型或格式正确的日期字符串 | | ||
| `time` | 时间值,可以是 TIME 类型或格式正确的时间字符串 | | ||
| `string` | 日期时间字符串或者 datetime 类型 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
描述错误
- 返回一个 TIME 类型值,格式为 `HH:MM:SS`,表示从起点时间(00:00:00)开始计算的时间。 | ||
- 如果输入的 `<seconds>` 为 NULL,函数返回 NULL。 | ||
返回一个秒数转换为 TIME 类型的值 | ||
- 若输入秒数超出 TIME 类型的有效范围(-838:59:59 至 838:59:59,对应秒数范围 -3023999 至 3023999),返回错误; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sec_to_time超出范围后不报错。
日期时间匹配方式,用两根指针指向两字符串起始位置 | ||
1. 当遇格式字符串到 % 符号时,会根据 %下一个字母匹配时间字符对应的时间部分,若不匹配(如 %Y 匹配日期时间部分却为 10:10:10 或者 % 不支持解析的字符如 %*),则返回 NULL,匹配成功则移动到下一个字符解析。 | ||
2. 任意时刻两串中的任一个遇到空格字符,直接跳过解析下一个字符串 | ||
3. 当遇到普通字母的匹配,则查看两字符串现在指针所指向的字符是否相等,不相等则返回 NULL,相等则解析下一个字符 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
报错,等待行为变更
3. 当遇到普通字母的匹配,则查看两字符串现在指针所指向的字符是否相等,不相等则返回 NULL,相等则解析下一个字符 | ||
4. 当任日期指针指向字符串末尾时,若日期时间只包含日期部分,则格式字符串会检查是否包含匹配时间部分的字符(如 %H),若包含,则会设置时间部分为 00:00:00。 | ||
5. 当格式字符串指向末尾时,匹配结束。 | ||
6. 最后检查匹配时间部分是否合法(如月份必须在 [1,12] 区间内),如果不合法,则返回 NULL,合法则返回解析出的日期时间 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
6. 最后检查匹配时间部分是否合法(如月份必须在 [1,12] 区间内),如果不合法,则返回 NULL,合法则返回解析出的日期时间 | ||
|
||
|
||
- 若 <datetime_str> 与 <format> 格式不匹配(如字符串为 2023/13/01 而格式为 %Y-%m-%d),返回 NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这条在上面描述了吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
等待行为变更
- 若 <datetime_str> 与 <format> 格式不匹配(如字符串为 2023/13/01 而格式为 %Y-%m-%d),返回 NULL; | ||
- 若任一参数为 NULL,返回 NULL; | ||
- 若 <format> 为空字符串,返回 NULL; | ||
- 若 <datetime_str> 缺少时间部分(仅日期),解析后时间部分默认为 00:00:00;若缺少日期部分(仅时间),日期部分默认为 0000-00-00(无效日期,返回 NULL)。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
报错,等待行为变更,不需要描述默认为多少了
+---------------------+ | ||
|
||
-- 仅时间字符串(日期无效,返回空字符串) | ||
SELECT STR_TO_DATE('15:30:45', '%H:%i:%s') AS result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我们现在是这个行为吗?这个应该有bug的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
得记录个jira
|
||
特殊情况: | ||
- 如果任何参数为 NULL,返回 NULL。 | ||
- 当输入的时区不合法的时候,返回NULL。 时区的设置参考 [时区管理](../../../../admin-manual/cluster-management/time-zone)。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不合法的时候已经是报错了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
整个看一下
bc7e8ba
to
16b75ec
Compare
16b75ec
to
ac6f98b
Compare
+--------+ | ||
|
||
--- 包含 scale 的时间,会把小数部分差距算入 | ||
SELECT SECONDS_DIFF('2023-07-13 12:00:00.123', '2023-07-13 11:59:59') AS result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个例子不恰当,本来不带小数也是1秒
Versions
Languages
Docs Checklist