Commit c67149b8 authored by Alexander Barkov's avatar Alexander Barkov

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.
parent 9e845107
......@@ -48,7 +48,7 @@ now()-curdate()*1000000-curtime()
select strcmp(current_timestamp(),concat(current_date()," ",current_time())) as exp;
exp
0
select strcmp(localtime(),concat(current_date()," ",current_time())) as exp;
select strcmp(localtime(),current_time()) as exp;
exp
0
select strcmp(localtimestamp(),concat(current_date()," ",current_time())) as exp;
......@@ -6397,3 +6397,32 @@ SET @@timestamp= DEFAULT;
#
# End of 10.5 tests
#
#
# Start of 11.6 tests
#
#
# MDEV-34829 LOCALTIME returns a wrong data type
#
SET timestamp=UNIX_TIMESTAMP('2024-08-28 14:47:00');
SELECT LOCALTIME;
LOCALTIME
14:47:00
EXPLAIN EXTENDED SELECT LOCALTIME;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 select curtime() AS `LOCALTIME`
CREATE TABLE t1 AS SELECT LOCALTIME;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`LOCALTIME` time NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
SELECT * FROM t1;
LOCALTIME
14:47:00
DROP TABLE t1;
SET timestamp=DEFAULT;
#
# End of 11.6 tests
#
......@@ -25,7 +25,7 @@ select sec_to_time(90011e-1), sec_to_time(1234567890123e30);
select sec_to_time(1234567890123), sec_to_time('99999999999999999999999999999');
select now()-curdate()*1000000-curtime();
select strcmp(current_timestamp(),concat(current_date()," ",current_time())) as exp;
select strcmp(localtime(),concat(current_date()," ",current_time())) as exp;
select strcmp(localtime(),current_time()) as exp;
select strcmp(localtimestamp(),concat(current_date()," ",current_time())) as exp;
select date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w") as exp;
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;
--echo #
--echo # End of 10.5 tests
--echo #
--echo #
--echo # Start of 11.6 tests
--echo #
--echo #
--echo # MDEV-34829 LOCALTIME returns a wrong data type
--echo #
SET timestamp=UNIX_TIMESTAMP('2024-08-28 14:47:00');
SELECT LOCALTIME;
EXPLAIN EXTENDED SELECT LOCALTIME;
CREATE TABLE t1 AS SELECT LOCALTIME;
SHOW CREATE TABLE t1;
SELECT * FROM t1;
DROP TABLE t1;
SET timestamp=DEFAULT;
--echo #
--echo # End of 11.6 tests
--echo #
......@@ -13,7 +13,7 @@ utc_timestamp(1) 2010-12-31 22:01:01.1
utc_time(2) 22:01:01.12
current_time(3) 01:01:01.123
current_timestamp(4) 2011-01-01 01:01:01.1234
localtime(5) 2011-01-01 01:01:01.12345
localtime(5) 01:01:01.12345
localtimestamp(6) 2011-01-01 01:01:01.123456
time_to_sec('12:34:56') 45296
time_to_sec('12:34:56.789') 45296.789
......@@ -45,7 +45,7 @@ t1 CREATE TABLE `t1` (
`utc_time(2)` time(2) NOT NULL,
`current_time(3)` time(3) NOT NULL,
`current_timestamp(4)` datetime(4) NOT NULL,
`localtime(5)` datetime(5) NOT NULL,
`localtime(5)` time(5) NOT NULL,
`localtimestamp(6)` datetime(6) NOT NULL,
`time_to_sec(123456)` bigint(17) DEFAULT NULL,
`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
utc_time(2) 22:01:01.12
current_time(3) 01:01:01.123
current_timestamp(4) 2011-01-01 01:01:01.1234
localtime(5) 2011-01-01 01:01:01.12345
localtime(5) 01:01:01.12345
localtimestamp(6) 2011-01-01 01:01:01.123456
time_to_sec(123456) 45296
time_to_sec('12:34:56.789') 45296.789
......
......@@ -2627,7 +2627,7 @@ a
16:46:40
1970-01-12 16:46:40
16:46:40
1970-01-12 16:46:40
16:46:40
1970-01-12 16:46:40
1970-01-12 16:46:40
1000000
......
......@@ -38,9 +38,9 @@ create or replace table t1 (a datetime as (curtime()) PERSISTENT);
ERROR HY000: Function or expression 'curtime()' cannot be used in the GENERATED ALWAYS AS clause of `a`
# LOCALTIME(), LOCALTIME
create or replace table t1 (a datetime, b varchar(10) as (localtime()) PERSISTENT);
ERROR HY000: Function or expression 'current_timestamp()' cannot be used in the GENERATED ALWAYS AS clause of `b`
ERROR HY000: Function or expression 'curtime()' cannot be used in the GENERATED ALWAYS AS clause of `b`
create or replace table t1 (a datetime, b varchar(10) as (localtime) PERSISTENT);
ERROR HY000: Function or expression 'current_timestamp()' cannot be used in the GENERATED ALWAYS AS clause of `b`
ERROR HY000: Function or expression 'curtime()' cannot be used in the GENERATED ALWAYS AS clause of `b`
# LOCALTIMESTAMP, LOCALTIMESTAMP()(v4.0.6)
create or replace table t1 (a datetime, b varchar(10) as (localtimestamp()) PERSISTENT);
ERROR HY000: Function or expression 'current_timestamp()' cannot be used in the GENERATED ALWAYS AS clause of `b`
......
......@@ -352,7 +352,7 @@ SYMBOL symbols[] = {
{ "LIST", SYM(LIST_SYM)},
{ "LOAD", SYM(LOAD)},
{ "LOCAL", SYM(LOCAL_SYM)},
{ "LOCALTIME", SYM(NOW_SYM)},
{ "LOCALTIME", SYM(CURTIME)},
{ "LOCALTIMESTAMP", SYM(NOW_SYM)},
{ "LOCK", SYM(LOCK_SYM)},
{ "LOCKED", SYM(LOCKED_SYM)},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment