Skip to content
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

Insert a special datetime with time_zone results in loss of precision #49555

Closed
Defined2014 opened this issue Dec 18, 2023 · 6 comments · Fixed by #50958
Closed

Insert a special datetime with time_zone results in loss of precision #49555

Defined2014 opened this issue Dec 18, 2023 · 6 comments · Fixed by #50958
Assignees
Labels
affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@Defined2014
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

create table t(a datetime(3));
insert into t values ('2020-01-01 12:00:00.123456 +0600 PST'); # The format is Golang’s default format
insert into t values ('2020-01-01 12:00:00.123456 -0600 PST');
select * from t;

2. What did you expect to see? (Required)

Got error during insert or keep result like 2020-01-01 12:00:00.123

MySQL will report error during insert.

3. What did you see instead (Required)

mysql> select * from t;
+-------------------------+
| a                       |
+-------------------------+
| 2020-01-01 12:00:00.123 |
| 2020-01-01 12:00:00.000 |
+-------------------------+
2 rows in set (0.01 sec)

4. What is your TiDB version? (Required)

23953a7

@Defined2014 Defined2014 added type/bug The issue is confirmed as a bug. sig/execution SIG execution labels Dec 18, 2023
@Defined2014
Copy link
Contributor Author

Defined2014 commented Dec 18, 2023

Why the results are different in case of + and - is because code below.

if unicode.IsPunct(rune(s[i])) {

unicode.IsPunct('+') will return false which is difference between unicode.IsPunct('-').

@SeaRise
Copy link
Contributor

SeaRise commented Feb 2, 2024

/assign @SeaRise

@SeaRise
Copy link
Contributor

SeaRise commented Feb 2, 2024

use test;
drop table if exists t;
create table t(a varchar(50));
insert into t values ('2020-01-01 12:00:00.123456 -0600 PST');
select cast(a as datetime(3)) from t;

--tidb
+-------------------------+
| cast(a as datetime(3))  |
+-------------------------+
| 2020-01-01 12:00:00.000 |
+-------------------------+

--mysql
+-------------------------+
| cast(a as datetime(3))  |
+-------------------------+
| 2020-01-01 12:00:00.123 |
+-------------------------+

@SeaRise
Copy link
Contributor

SeaRise commented Feb 4, 2024

/assign @SeaRise

@SeaRise
Copy link
Contributor

SeaRise commented Feb 4, 2024

tiflash and tikv also have similar problems.
pingcap/tiflash#8754
tikv/tikv#16492

@SeaRise
Copy link
Contributor

SeaRise commented Feb 4, 2024

related codes are introduced by #9933 and #37820

@ti-chi-bot ti-chi-bot bot added affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. and removed may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 may-affects-7.5 labels Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug.
Projects
None yet
3 participants