Skip to content

Commit c67149b

Browse files
committed
MDEV-34829 LOCALTIME returns a wrong data type
Changing the alias LOCALTIME->CURRENT_TIMESTAMP to LOCALTIME->CURRENT_TIME. This changes the return type of LOCALTIME from DATETIME to TIME, according to the SQL Standard.
1 parent 9e84510 commit c67149b

File tree

6 files changed

+59
-9
lines changed

6 files changed

+59
-9
lines changed

mysql-test/main/func_time.result

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ now()-curdate()*1000000-curtime()
4848
select strcmp(current_timestamp(),concat(current_date()," ",current_time())) as exp;
4949
exp
5050
0
51-
select strcmp(localtime(),concat(current_date()," ",current_time())) as exp;
51+
select strcmp(localtime(),current_time()) as exp;
5252
exp
5353
0
5454
select strcmp(localtimestamp(),concat(current_date()," ",current_time())) as exp;
@@ -6397,3 +6397,32 @@ SET @@timestamp= DEFAULT;
63976397
#
63986398
# End of 10.5 tests
63996399
#
6400+
#
6401+
# Start of 11.6 tests
6402+
#
6403+
#
6404+
# MDEV-34829 LOCALTIME returns a wrong data type
6405+
#
6406+
SET timestamp=UNIX_TIMESTAMP('2024-08-28 14:47:00');
6407+
SELECT LOCALTIME;
6408+
LOCALTIME
6409+
14:47:00
6410+
EXPLAIN EXTENDED SELECT LOCALTIME;
6411+
id select_type table type possible_keys key key_len ref rows filtered Extra
6412+
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
6413+
Warnings:
6414+
Note 1003 select curtime() AS `LOCALTIME`
6415+
CREATE TABLE t1 AS SELECT LOCALTIME;
6416+
SHOW CREATE TABLE t1;
6417+
Table Create Table
6418+
t1 CREATE TABLE `t1` (
6419+
`LOCALTIME` time NOT NULL
6420+
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
6421+
SELECT * FROM t1;
6422+
LOCALTIME
6423+
14:47:00
6424+
DROP TABLE t1;
6425+
SET timestamp=DEFAULT;
6426+
#
6427+
# End of 11.6 tests
6428+
#

mysql-test/main/func_time.test

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ select sec_to_time(90011e-1), sec_to_time(1234567890123e30);
2525
select sec_to_time(1234567890123), sec_to_time('99999999999999999999999999999');
2626
select now()-curdate()*1000000-curtime();
2727
select strcmp(current_timestamp(),concat(current_date()," ",current_time())) as exp;
28-
select strcmp(localtime(),concat(current_date()," ",current_time())) as exp;
28+
select strcmp(localtime(),current_time()) as exp;
2929
select strcmp(localtimestamp(),concat(current_date()," ",current_time())) as exp;
3030
select date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w") as exp;
3131
select date_format("1997-01-02", concat("%M %W %D ","%Y %y %m %d %h %i %s %w")) as exp;
@@ -3249,3 +3249,24 @@ SET @@timestamp= DEFAULT;
32493249
--echo #
32503250
--echo # End of 10.5 tests
32513251
--echo #
3252+
3253+
--echo #
3254+
--echo # Start of 11.6 tests
3255+
--echo #
3256+
3257+
--echo #
3258+
--echo # MDEV-34829 LOCALTIME returns a wrong data type
3259+
--echo #
3260+
3261+
SET timestamp=UNIX_TIMESTAMP('2024-08-28 14:47:00');
3262+
SELECT LOCALTIME;
3263+
EXPLAIN EXTENDED SELECT LOCALTIME;
3264+
CREATE TABLE t1 AS SELECT LOCALTIME;
3265+
SHOW CREATE TABLE t1;
3266+
SELECT * FROM t1;
3267+
DROP TABLE t1;
3268+
SET timestamp=DEFAULT;
3269+
3270+
--echo #
3271+
--echo # End of 11.6 tests
3272+
--echo #

mysql-test/main/func_time_hires.result

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ utc_timestamp(1) 2010-12-31 22:01:01.1
1313
utc_time(2) 22:01:01.12
1414
current_time(3) 01:01:01.123
1515
current_timestamp(4) 2011-01-01 01:01:01.1234
16-
localtime(5) 2011-01-01 01:01:01.12345
16+
localtime(5) 01:01:01.12345
1717
localtimestamp(6) 2011-01-01 01:01:01.123456
1818
time_to_sec('12:34:56') 45296
1919
time_to_sec('12:34:56.789') 45296.789
@@ -45,7 +45,7 @@ t1 CREATE TABLE `t1` (
4545
`utc_time(2)` time(2) NOT NULL,
4646
`current_time(3)` time(3) NOT NULL,
4747
`current_timestamp(4)` datetime(4) NOT NULL,
48-
`localtime(5)` datetime(5) NOT NULL,
48+
`localtime(5)` time(5) NOT NULL,
4949
`localtimestamp(6)` datetime(6) NOT NULL,
5050
`time_to_sec(123456)` bigint(17) DEFAULT NULL,
5151
`time_to_sec('12:34:56.789')` decimal(19,3) DEFAULT NULL
@@ -60,7 +60,7 @@ utc_timestamp(1) 2010-12-31 22:01:01.1
6060
utc_time(2) 22:01:01.12
6161
current_time(3) 01:01:01.123
6262
current_timestamp(4) 2011-01-01 01:01:01.1234
63-
localtime(5) 2011-01-01 01:01:01.12345
63+
localtime(5) 01:01:01.12345
6464
localtimestamp(6) 2011-01-01 01:01:01.123456
6565
time_to_sec(123456) 45296
6666
time_to_sec('12:34:56.789') 45296.789

mysql-test/suite/binlog/r/binlog_unsafe.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2627,7 +2627,7 @@ a
26272627
16:46:40
26282628
1970-01-12 16:46:40
26292629
16:46:40
2630-
1970-01-12 16:46:40
2630+
16:46:40
26312631
1970-01-12 16:46:40
26322632
1970-01-12 16:46:40
26332633
1000000

mysql-test/suite/vcol/r/vcol_blocked_sql_funcs.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ create or replace table t1 (a datetime as (curtime()) PERSISTENT);
3838
ERROR HY000: Function or expression 'curtime()' cannot be used in the GENERATED ALWAYS AS clause of `a`
3939
# LOCALTIME(), LOCALTIME
4040
create or replace table t1 (a datetime, b varchar(10) as (localtime()) PERSISTENT);
41-
ERROR HY000: Function or expression 'current_timestamp()' cannot be used in the GENERATED ALWAYS AS clause of `b`
41+
ERROR HY000: Function or expression 'curtime()' cannot be used in the GENERATED ALWAYS AS clause of `b`
4242
create or replace table t1 (a datetime, b varchar(10) as (localtime) PERSISTENT);
43-
ERROR HY000: Function or expression 'current_timestamp()' cannot be used in the GENERATED ALWAYS AS clause of `b`
43+
ERROR HY000: Function or expression 'curtime()' cannot be used in the GENERATED ALWAYS AS clause of `b`
4444
# LOCALTIMESTAMP, LOCALTIMESTAMP()(v4.0.6)
4545
create or replace table t1 (a datetime, b varchar(10) as (localtimestamp()) PERSISTENT);
4646
ERROR HY000: Function or expression 'current_timestamp()' cannot be used in the GENERATED ALWAYS AS clause of `b`

sql/lex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ SYMBOL symbols[] = {
352352
{ "LIST", SYM(LIST_SYM)},
353353
{ "LOAD", SYM(LOAD)},
354354
{ "LOCAL", SYM(LOCAL_SYM)},
355-
{ "LOCALTIME", SYM(NOW_SYM)},
355+
{ "LOCALTIME", SYM(CURTIME)},
356356
{ "LOCALTIMESTAMP", SYM(NOW_SYM)},
357357
{ "LOCK", SYM(LOCK_SYM)},
358358
{ "LOCKED", SYM(LOCKED_SYM)},

0 commit comments

Comments
 (0)