Skip to content

Commit dad24a5

Browse files
abarkovvuvova
authored andcommitted
MDEV-15751 CURRENT_TIMESTAMP should return a TIMESTAMP [WITH TIME ZONE?]
Changing the return type of the following functions: - CURRENT_TIMESTAMP, CURRENT_TIMESTAMP(), NOW() - SYSDATE() - FROM_UNIXTIME() from DATETIME to TIMESTAMP. Note, the old function NOW() returning DATETIME is still available as LOCALTIMESTAMP or LOCALTIMESTAMP(), e.g.: SELECT LOCALTIMESTAMP, -- DATETIME CURRENT_TIMESTAMP; -- TIMESTAMP The change in the functions return data type fixes some problems that occurred near a DST change: - Problem #1 INSERT INTO t1 (timestamp_field) VALUES (CURRENT_TIMESTAMP); INSERT INTO t1 (timestamp_field) VALUES (COALESCE(CURRENT_TIMESTAMP)); could result into two different values inserted. - Problem #2 INSERT INTO t1 (timestamp_field) VALUES (FROM_UNIXTIME(1288477526)); INSERT INTO t1 (timestamp_field) VALUES (FROM_UNIXTIME(1288477526+3600)); could result into two equal TIMESTAMP values near a DST change. Additional changes: - FROM_UNIXTIME(0) now returns SQL NULL instead of '1970-01-01 00:00:00' (assuming time_zone='+00:00') - UNIX_TIMESTAMP('1970-01-01 00:00:00') now returns SQL NULL instead of 0 (assuming time_zone='+00:00' These additional changes are needed for consistency with TIMESTAMP fields, which cannot store '1970-01-01 00:00:00 +00:00'.
1 parent 3624fb7 commit dad24a5

30 files changed

+753
-163
lines changed

mysql-test/main/create.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ drop table t2;
128128
create table t2 select now() as a , curtime() as b, curdate() as c , 1+1 as d , 1.0 + 1 as e , 33333333333333333 + 3 as f;
129129
describe t2;
130130
Field Type Null Key Default Extra
131-
a datetime NO NULL
131+
a timestamp NO NULL
132132
b time NO NULL
133133
c date NO NULL
134134
d int(3) NO NULL

mysql-test/main/func_group.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,12 +781,12 @@ insert into t1 values (now());
781781
create table t2 select f2 from (select max(now()) f2 from t1) a;
782782
show columns from t2;
783783
Field Type Null Key Default Extra
784-
f2 datetime YES NULL
784+
f2 timestamp YES NULL
785785
drop table t2;
786786
create table t2 select f2 from (select now() f2 from t1) a;
787787
show columns from t2;
788788
Field Type Null Key Default Extra
789-
f2 datetime NO NULL
789+
f2 timestamp NO NULL
790790
drop table t2, t1;
791791
CREATE TABLE t1(
792792
id int PRIMARY KEY,

mysql-test/main/func_time.result

Lines changed: 123 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,9 @@ from_unixtime(2147483647)
583583
2038-01-19 06:14:07
584584
select from_unixtime(0);
585585
from_unixtime(0)
586-
1970-01-01 03:00:00
586+
NULL
587+
Warnings:
588+
Warning 1292 Truncated incorrect unixtime value: '0.0'
587589
select unix_timestamp(from_unixtime(2147483647));
588590
unix_timestamp(from_unixtime(2147483647))
589591
2147483647
@@ -6323,10 +6325,12 @@ TIME('- 01:00:00') TIME('- 1 01:00:00')
63236325
SET time_zone='+00:00';
63246326
SELECT NULLIF(FROM_UNIXTIME('foo'), '2012-12-12 21:10:14');
63256327
NULLIF(FROM_UNIXTIME('foo'), '2012-12-12 21:10:14')
6326-
1970-01-01 00:00:00
6328+
NULL
63276329
Warnings:
63286330
Warning 1292 Truncated incorrect DECIMAL value: 'foo'
6331+
Warning 1292 Truncated incorrect unixtime value: '0.0'
63296332
Warning 1292 Truncated incorrect DECIMAL value: 'foo'
6333+
Warning 1292 Truncated incorrect unixtime value: '0.0'
63306334
SET time_zone=DEFAULT;
63316335
#
63326336
# MDEV-18402 Assertion `sec.sec() <= 59' failed in Item_func_maketime::get_date
@@ -6426,3 +6430,120 @@ SET timestamp=DEFAULT;
64266430
#
64276431
# End of 11.6 tests
64286432
#
6433+
#
6434+
# Start of 11.7 tests
6435+
#
6436+
#
6437+
# MDEV-15751 CURRENT_TIMESTAMP should return a TIMESTAMP [WITH TIME ZONE?]
6438+
#
6439+
CREATE TABLE t1 (localtimestamp TIMESTAMP);
6440+
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'localtimestamp TIMESTAMP)' at line 1
6441+
CREATE TABLE t1 (current_timestamp TIMESTAMP);
6442+
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'current_timestamp TIMESTAMP)' at line 1
6443+
CREATE TABLE t1 AS
6444+
SELECT
6445+
localtimestamp,
6446+
localtimestamp(),
6447+
localtimestamp(0),
6448+
localtimestamp(1),
6449+
localtimestamp(2),
6450+
localtimestamp(3),
6451+
localtimestamp(4),
6452+
localtimestamp(5),
6453+
localtimestamp(6);
6454+
SHOW CREATE TABLE t1;
6455+
Table Create Table
6456+
t1 CREATE TABLE `t1` (
6457+
`localtimestamp` datetime NOT NULL,
6458+
`localtimestamp()` datetime NOT NULL,
6459+
`localtimestamp(0)` datetime NOT NULL,
6460+
`localtimestamp(1)` datetime(1) NOT NULL,
6461+
`localtimestamp(2)` datetime(2) NOT NULL,
6462+
`localtimestamp(3)` datetime(3) NOT NULL,
6463+
`localtimestamp(4)` datetime(4) NOT NULL,
6464+
`localtimestamp(5)` datetime(5) NOT NULL,
6465+
`localtimestamp(6)` datetime(6) NOT NULL
6466+
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
6467+
DROP TABLE t1;
6468+
CREATE TABLE t1 AS
6469+
SELECT
6470+
current_timestamp(),
6471+
current_timestamp(0),
6472+
current_timestamp(1),
6473+
current_timestamp(2),
6474+
current_timestamp(3),
6475+
current_timestamp(4),
6476+
current_timestamp(5),
6477+
current_timestamp(6);
6478+
SHOW CREATE TABLE t1;
6479+
Table Create Table
6480+
t1 CREATE TABLE `t1` (
6481+
`current_timestamp()` timestamp NOT NULL,
6482+
`current_timestamp(0)` timestamp NOT NULL,
6483+
`current_timestamp(1)` timestamp(1) NOT NULL,
6484+
`current_timestamp(2)` timestamp(2) NOT NULL,
6485+
`current_timestamp(3)` timestamp(3) NOT NULL,
6486+
`current_timestamp(4)` timestamp(4) NOT NULL,
6487+
`current_timestamp(5)` timestamp(5) NOT NULL,
6488+
`current_timestamp(6)` timestamp(6) NOT NULL
6489+
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
6490+
DROP TABLE t1;
6491+
CREATE TABLE t1 AS
6492+
SELECT
6493+
sysdate(),
6494+
sysdate(0),
6495+
sysdate(1),
6496+
sysdate(2),
6497+
sysdate(3),
6498+
sysdate(4),
6499+
sysdate(5),
6500+
sysdate(6);
6501+
SHOW CREATE TABLE t1;
6502+
Table Create Table
6503+
t1 CREATE TABLE `t1` (
6504+
`sysdate()` timestamp NOT NULL,
6505+
`sysdate(0)` timestamp NOT NULL,
6506+
`sysdate(1)` timestamp(1) NOT NULL,
6507+
`sysdate(2)` timestamp(2) NOT NULL,
6508+
`sysdate(3)` timestamp(3) NOT NULL,
6509+
`sysdate(4)` timestamp(4) NOT NULL,
6510+
`sysdate(5)` timestamp(5) NOT NULL,
6511+
`sysdate(6)` timestamp(6) NOT NULL
6512+
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
6513+
DROP TABLE t1;
6514+
CREATE TABLE t1 AS
6515+
SELECT
6516+
from_unixtime(1000000e0),
6517+
from_unixtime(1000000),
6518+
from_unixtime(1000000.1),
6519+
from_unixtime(1000000.12),
6520+
from_unixtime(1000000.123),
6521+
from_unixtime(1000000.1234),
6522+
from_unixtime(1000000.12345),
6523+
from_unixtime(1000000.123456),
6524+
from_unixtime(1000000.1234567),
6525+
from_unixtime(1000000.12345678),
6526+
from_unixtime(1000000.123456789),
6527+
from_unixtime(1000000.1234567891),
6528+
from_unixtime(1000000.12345678912);
6529+
SHOW CREATE TABLE t1;
6530+
Table Create Table
6531+
t1 CREATE TABLE `t1` (
6532+
`from_unixtime(1000000e0)` timestamp(6) NULL DEFAULT NULL,
6533+
`from_unixtime(1000000)` timestamp NULL DEFAULT NULL,
6534+
`from_unixtime(1000000.1)` timestamp(1) NULL DEFAULT NULL,
6535+
`from_unixtime(1000000.12)` timestamp(2) NULL DEFAULT NULL,
6536+
`from_unixtime(1000000.123)` timestamp(3) NULL DEFAULT NULL,
6537+
`from_unixtime(1000000.1234)` timestamp(4) NULL DEFAULT NULL,
6538+
`from_unixtime(1000000.12345)` timestamp(5) NULL DEFAULT NULL,
6539+
`from_unixtime(1000000.123456)` timestamp(6) NULL DEFAULT NULL,
6540+
`from_unixtime(1000000.1234567)` timestamp(6) NULL DEFAULT NULL,
6541+
`from_unixtime(1000000.12345678)` timestamp(6) NULL DEFAULT NULL,
6542+
`from_unixtime(1000000.123456789)` timestamp(6) NULL DEFAULT NULL,
6543+
`from_unixtime(1000000.1234567891)` timestamp(6) NULL DEFAULT NULL,
6544+
`from_unixtime(1000000.12345678912)` timestamp(6) NULL DEFAULT NULL
6545+
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
6546+
DROP TABLE t1;
6547+
#
6548+
# End of 11.7 tests
6549+
#

mysql-test/main/func_time.test

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3270,3 +3270,79 @@ SET timestamp=DEFAULT;
32703270
--echo #
32713271
--echo # End of 11.6 tests
32723272
--echo #
3273+
3274+
--echo #
3275+
--echo # Start of 11.7 tests
3276+
--echo #
3277+
3278+
--echo #
3279+
--echo # MDEV-15751 CURRENT_TIMESTAMP should return a TIMESTAMP [WITH TIME ZONE?]
3280+
--echo #
3281+
3282+
--error ER_PARSE_ERROR
3283+
CREATE TABLE t1 (localtimestamp TIMESTAMP);
3284+
--error ER_PARSE_ERROR
3285+
CREATE TABLE t1 (current_timestamp TIMESTAMP);
3286+
3287+
CREATE TABLE t1 AS
3288+
SELECT
3289+
localtimestamp,
3290+
localtimestamp(),
3291+
localtimestamp(0),
3292+
localtimestamp(1),
3293+
localtimestamp(2),
3294+
localtimestamp(3),
3295+
localtimestamp(4),
3296+
localtimestamp(5),
3297+
localtimestamp(6);
3298+
SHOW CREATE TABLE t1;
3299+
DROP TABLE t1;
3300+
3301+
3302+
CREATE TABLE t1 AS
3303+
SELECT
3304+
current_timestamp(),
3305+
current_timestamp(0),
3306+
current_timestamp(1),
3307+
current_timestamp(2),
3308+
current_timestamp(3),
3309+
current_timestamp(4),
3310+
current_timestamp(5),
3311+
current_timestamp(6);
3312+
SHOW CREATE TABLE t1;
3313+
DROP TABLE t1;
3314+
3315+
CREATE TABLE t1 AS
3316+
SELECT
3317+
sysdate(),
3318+
sysdate(0),
3319+
sysdate(1),
3320+
sysdate(2),
3321+
sysdate(3),
3322+
sysdate(4),
3323+
sysdate(5),
3324+
sysdate(6);
3325+
SHOW CREATE TABLE t1;
3326+
DROP TABLE t1;
3327+
3328+
CREATE TABLE t1 AS
3329+
SELECT
3330+
from_unixtime(1000000e0),
3331+
from_unixtime(1000000),
3332+
from_unixtime(1000000.1),
3333+
from_unixtime(1000000.12),
3334+
from_unixtime(1000000.123),
3335+
from_unixtime(1000000.1234),
3336+
from_unixtime(1000000.12345),
3337+
from_unixtime(1000000.123456),
3338+
from_unixtime(1000000.1234567),
3339+
from_unixtime(1000000.12345678),
3340+
from_unixtime(1000000.123456789),
3341+
from_unixtime(1000000.1234567891),
3342+
from_unixtime(1000000.12345678912);
3343+
SHOW CREATE TABLE t1;
3344+
DROP TABLE t1;
3345+
3346+
--echo #
3347+
--echo # End of 11.7 tests
3348+
--echo #

mysql-test/main/func_time_hires.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ t1 CREATE TABLE `t1` (
3939
`sec_to_time(12345)` time DEFAULT NULL,
4040
`sec_to_time(12345.6789)` time(4) DEFAULT NULL,
4141
`sec_to_time(1234567e-2)` time(6) DEFAULT NULL,
42-
`now()` datetime NOT NULL,
42+
`now()` timestamp NOT NULL,
4343
`curtime(0)` time NOT NULL,
4444
`utc_timestamp(1)` datetime(1) NOT NULL,
4545
`utc_time(2)` time(2) NOT NULL,
4646
`current_time(3)` time(3) NOT NULL,
47-
`current_timestamp(4)` datetime(4) NOT NULL,
47+
`current_timestamp(4)` timestamp(4) NOT NULL,
4848
`localtime(5)` time(5) NOT NULL,
4949
`localtimestamp(6)` datetime(6) NOT NULL,
5050
`time_to_sec(123456)` bigint(17) DEFAULT NULL,

mysql-test/main/ps.result

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4574,21 +4574,21 @@ EXECUTE stmt USING CURRENT_TIMESTAMP;
45744574
SHOW CREATE TABLE t1;
45754575
Table Create Table
45764576
t1 CREATE TABLE `t1` (
4577-
`c1` datetime NOT NULL
4577+
`c1` timestamp NOT NULL
45784578
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
45794579
DROP TABLE t1;
45804580
EXECUTE stmt USING CURRENT_TIMESTAMP(3);
45814581
SHOW CREATE TABLE t1;
45824582
Table Create Table
45834583
t1 CREATE TABLE `t1` (
4584-
`c1` datetime(3) NOT NULL
4584+
`c1` timestamp(3) NOT NULL
45854585
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
45864586
DROP TABLE t1;
45874587
EXECUTE stmt USING CURRENT_TIMESTAMP(6);
45884588
SHOW CREATE TABLE t1;
45894589
Table Create Table
45904590
t1 CREATE TABLE `t1` (
4591-
`c1` datetime(6) NOT NULL
4591+
`c1` timestamp(6) NOT NULL
45924592
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
45934593
DROP TABLE t1;
45944594
EXECUTE stmt USING CURRENT_TIME;

mysql-test/main/timezone.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ DROP TABLE t1;
5353
select unix_timestamp('1970-01-01 01:00:00'),
5454
unix_timestamp('1970-01-01 01:00:01');
5555
unix_timestamp('1970-01-01 01:00:00') unix_timestamp('1970-01-01 01:00:01')
56-
0 1
56+
NULL 1
5757
select unix_timestamp('1969-12-31 23:59:59'), unix_timestamp('1970-01-01 00:00:00'), unix_timestamp('1970-01-01 00:59:59');
5858
unix_timestamp('1969-12-31 23:59:59') unix_timestamp('1970-01-01 00:00:00') unix_timestamp('1970-01-01 00:59:59')
5959
NULL NULL NULL

0 commit comments

Comments
 (0)