Skip to content

[Bug]: BIT_COUNT/SEC_TO_TIME read DATE/DATETIME/TIME arguments as text prefixes ('2024-01-01' -> 2024, '01:02:03' -> 1) #31906

Closed as duplicate

Description

@MatrixAdventurer

问题描述

BIT_COUNT() 和 SEC_TO_TIME() 收到 DATE/DATETIME/TIME 参数时,MO 先把时间值格式化成文本,再按"字符串转整数"取数字前缀:'2024-01-01' 变成 2024,'01:02:03' 变成 1,并报 1292 Truncated incorrect INTEGER value。MySQL 把时间值按数字形式转换(20240101、20240101100000、10203),没有警告。

所以 BIT_COUNT(date_col)、SEC_TO_TIME(time_col) 在 MO 上静默返回错误结果。

环境

  • 分支:main(c32e75a2,2026-10-30)
  • 对照:MySQL 8.4.9

复现步骤

create table t (d date, dt datetime, tm time);
insert into t values ('2024-01-01', '2024-01-01 10:00:00', '01:02:03');
select bit_count(d), bit_count(dt), bit_count(tm) from t;
show warnings;
select sec_to_time(d), sec_to_time(tm), sec_to_time(time'01:02:03') from t;
select bit_count(20240101), sec_to_time(10203);   -- 数字形式对照

实际结果(MO)

bit_count(d) = 7   bit_count(dt) = 7   bit_count(tm) = 1
Warning 1292 Truncated incorrect INTEGER value: '2024-01-01'
Warning 1292 Truncated incorrect INTEGER value: '2024-01-01 10:00:00'
Warning 1292 Truncated incorrect INTEGER value: '01:02:03'
sec_to_time(d) = 00:33:44   sec_to_time(tm) = 00:00:01   sec_to_time(time'01:02:03') = 00:00:01
bit_count(20240101) = 14   sec_to_time(10203) = 02:50:03

(7 = bit_count(2024),00:33:44 = 2024 秒,00:00:01 = 1 秒。)

期望结果(MySQL 8.4.9)

bit_count(d) = 14   bit_count(dt) = 15   bit_count(tm) = 10   (无警告)
sec_to_time(d) = 838:59:59(20240101 秒超出 TIME 上限,截断并警告)
sec_to_time(tm) = 02:50:03   sec_to_time(time'01:02:03') = 02:50:03

本操作由 LW 授权的 Grok Bot 智能体执行。

Activity

  1. added
    kind/bug
    on Oct 30, 2026
  2. XuPeng-SH commented on Nov 9, 2026

    @XuPeng-SH
    Contributor

    This issue is being consolidated into #31904 as the scalar-function side of temporal-to-numeric coercion. Preserve BIT_COUNT and SEC_TO_TIME results for DATE, DATETIME, and TIME, including warning and TIME-range behavior, alongside the bitwise-operator cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions