SET timestamp=UNIX_TIMESTAMP('2001-01-01 10:20:30.123456');
#
# Check that CURRENT_TIMESTAMP works as before
#
CREATE or replace TABLE t1 (event_time TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);
SHOW CREATE TABLE t1;
Table Create Table
...
...
@@ -261,9 +262,9 @@ t1 CREATE TABLE `t1` (
`event_time` timestamp(6) NOT NULL DEFAULT SYSDATE(2) ON UPDATE CURRENT_TIMESTAMP(6)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
Check default expressions
#
# Check default expressions
#
create or replace table t1 (a int default 1, b int default (a+1), c int default (a+b)) engine myisam;
show create table t1;
Table Create Table
...
...
@@ -275,26 +276,26 @@ t1 CREATE TABLE `t1` (
insert into t1 values ();
insert into t1 (a) values (2);
insert into t1 (a,b) values (10,20);
insert into t1 (a,b,c) values (100,200,300);
insert into t1 (a,b,c) values (100,200,400);
select * from t1;
a b c
1 2 3
2 3 5
10 20 30
100 200 300
100 200 400
truncate table t1;
insert delayed into t1 values ();
insert delayed into t1 (a) values (2);
insert delayed into t1 (a,b) values (10,20);
insert delayed into t1 (a,b,c) values (100,200,300);
insert delayed into t1 (a,b,c) values (100,200,400);
flush tables t1;
select * from t1;
a b c
1 2 3
2 3 5
10 20 30
100 200 300
create or replace table t1 (a int, b blob default (1), c blob default ("hello"), t text default (concat(a,b,c))) engine=myisam;
100 200 400
create or replace table t1 (a int, b blob default (1), c blob default "hello", t text default concat(a,b,c)) engine=myisam;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
...
...
@@ -329,15 +330,15 @@ drop table t1;
create table t1 (a int);
insert into t1 values(-1);
alter table t1 add b int default 1, add c int default -1, add d int default (1+1), add e timestamp;
select a,b,c,d,e > 0 from t1;
a b c d e > 0
-1 1 -1 2 1
select a,b,c,d,e from t1;
a b c d e
-1 1 -1 2 2001-01-01 10:20:30
insert into t1 values(10,10,10,10,0);
alter table t1 add f int default (1+1+1) null, add g int default (1+1+1+1) not null,add h int default (2+2+2+2);
select a,b,c,d,e > 0,f,g,h from t1;
a b c d e > 0 f g h
-1 1 -1 2 1 3 4 8
10 10 10 10 0 3 4 8
select a,b,c,d,e,f,g,h from t1;
a b c d e f g h
-1 1 -1 2 2001-01-01 10:20:30 3 4 8
10 10 10 10 0000-00-00 00:00:00 3 4 8
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
...
...
@@ -364,9 +365,9 @@ t2 CREATE TABLE `t2` (
`h` int(11) DEFAULT (2+2+2+2)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
insert into t2 (a) values (100);
select a,b,c,d,e > 0,f,g,h from t2;
a b c d e > 0 f g h
100 1 -1 2 1 3 4 8
select a,b,c,d,e,f,g,h from t2;
a b c d e f g h
100 1 -1 2 2001-01-01 10:20:30 3 4 8
drop table t1,t2;
create table t1 (a int default (1----1), b int default - 1, c int default +1, e int default (--1));
show create table t1;
...
...
@@ -384,17 +385,17 @@ a b c e
2 -1 1 1
2 -1 1 1
drop table t1;
create or replace can delete a table on error
#
# Create or replace can delete a table on error
#
create table t1 (a int);
create or replace table t1 (a int default b, b int default a);
ERROR 01000: Expression for field `a` is refering to uninitialized field `b`
show create table t1;
ERROR 42S02: Table 'test.t1' doesn't exist
Refering to other columns
#
# Refering to other columns
#
create or replace table t1 (a int default 1, b int default a);
create or replace table t1 (a int default 1, b int as (a));
create or replace table t1 (a int default b, b int default 1);
...
...
@@ -411,42 +412,34 @@ create or replace table t1 (a int default b, b int default (1+1));
ERROR 01000: Expression for field `a` is refering to uninitialized field `b`
create or replace table t1 (a int default 1, b int as (c), c int as (a+1));
ERROR 01000: Expression for field `b` is refering to uninitialized field `c`
CREATE TABLE t1 (a INT DEFAULT a);
ERROR 01000: Expression for field `a` is refering to uninitialized field `a`
CREATE TABLE t1 (a INT DEFAULT (DEFAULT(a)));
ERROR HY000: Field 'a' doesn't have a default value
CREATE TABLE t1 (a INT DEFAULT(DEFAULT(b)), b INT DEFAULT(DEFAULT(a)));
ERROR HY000: Field 'b' doesn't have a default value
CREATE TABLE t1 (a INT DEFAULT(DEFAULT(b)) NOT NULL, b INT DEFAULT(DEFAULT(a)) NOT NULL);
ERROR HY000: Field 'b' doesn't have a default value
drop table if exists t1;
Warnings:
Note 1051 Unknown table 'test.t1'
Allow defaults to refer to not default fields
create or replace table t1 (a int as (b), b int not null);
#
# Allow defaults to refer to not default fields
#
create or replace table t1 (a int default b, b int not null);
insert into t1 values();
Warnings:
Warning 1364 Field 'b' doesn't have a default value
insert into t1 (a) values(1);
Warnings:
Warning 1364 Field 'b' doesn't have a default value
Warning 1906 The value specified for computed column 'a' in table 't1' ignored
insert into t1 (b) values(2);
insert into t1 (a,b) values(3,4);
Warnings:
Warning 1906 The value specified for computed column 'a' in table 't1' ignored
select * from t1;
a b
0 0
0 0
1 0
2 2
4 4
3 4
drop table t1;
Error handling
#
# Error handling
#
create or replace table t1 (a bigint default xxx());
ERROR HY000: Function or expression '`xxx`' is not allowed for 'DEFAULT' of column/constraint 'a'
create or replace table t1 (a bigint default (select (1)));
...
...
@@ -459,9 +452,6 @@ CREATE TABLE t1 (a INT, b INT, c INT DEFAULT a DIV b);
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 'DIV b)' at line 1
CREATE TABLE t1 (a INT, b INT DEFAULT -a);
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 'a)' at line 1
drop table if exists t1;
Warnings:
Note 1051 Unknown table 'test.t1'
#
# Invalid DEFAULT expressions
#
...
...
@@ -1044,7 +1034,6 @@ DROP TABLE t1;
#
# DECIMAL + CURRENT_TIMESTAMP, no truncation
#
SET timestamp=UNIX_TIMESTAMP('2001-01-01 10:20:30.123456');
CREATE TABLE t1 (a DECIMAL(30,6) DEFAULT CURRENT_TIMESTAMP(6));
SHOW CREATE TABLE t1;
Table Create Table
...
...
@@ -1073,11 +1062,9 @@ INSERT INTO t1 VALUES();
ERROR 01000: Data truncated for column 'a' at row 1
SET sql_mode = DEFAULT;
DROP TABLE t1;
SET timestamp=DEFAULT;
#
# DECIMAL + CURRENT_TIME, no truncation
#
SET timestamp=UNIX_TIMESTAMP('2001-01-01 10:20:30.123456');
CREATE TABLE t1 (a DECIMAL(30,6) DEFAULT COALESCE(CURRENT_TIME(6)));
SHOW CREATE TABLE t1;
Table Create Table
...
...
@@ -1088,11 +1075,9 @@ INSERT INTO t1 VALUES();
Warnings:
Warning 1265 Data truncated for column 'a' at row 1
DROP TABLE t1;
SET timestamp=DEFAULT;
#
# DECIMAL + CURRENT_DATE, no truncation
#
SET timestamp=UNIX_TIMESTAMP('2001-01-01 10:20:30.123456');
CREATE TABLE t1 (a DECIMAL(30,6) DEFAULT COALESCE(CURRENT_DATE));
SHOW CREATE TABLE t1;
Table Create Table
...
...
@@ -1103,7 +1088,6 @@ INSERT INTO t1 VALUES();
Warnings:
Warning 1265 Data truncated for column 'a' at row 1
DROP TABLE t1;
SET timestamp=DEFAULT;
#
# COALESCE for SQL Standard <datetime value function>
#
...
...
@@ -1128,7 +1112,6 @@ t1 CREATE TABLE `t1` (
`a` time DEFAULT COALESCE(CURRENT_TIME)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
SET timestamp=UNIX_TIMESTAMP('2001-01-01 10:20:30.123456');
CREATE TABLE t1 (
a TIMESTAMP DEFAULT CURRENT_TIMESTAMP(6),
b TIMESTAMP DEFAULT COALESCE(CURRENT_TIMESTAMP(6))
...
...
@@ -1147,8 +1130,6 @@ SELECT * FROM t1;
a b
2001-01-01 10:20:30 2001-01-01 10:20:30
DROP TABLE t1;
SET timestamp=DEFAULT;
SET timestamp=UNIX_TIMESTAMP('2001-01-01 10:20:30.123456');
CREATE TABLE t1 (
a DECIMAL(30,0) DEFAULT CURRENT_TIMESTAMP(6),
b DECIMAL(30,0) DEFAULT COALESCE(CURRENT_TIMESTAMP(6))