Commit 4070d557 authored by Sergei Golubchik's avatar Sergei Golubchik

fix: CHECK and DEFAULT after CREATE ... SELECT

expression defaults and check constraints should behave as
constant default values - copied from fields, not copied from expressions
parent 3aff76f3
......@@ -3063,3 +3063,21 @@ t1 CREATE TABLE `t1` (
`c` int(11) DEFAULT (-a)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
create table t1 (a int default 5 check (a>10), b int default (5+5), c int as (a+b));
create table t2 as select a, b, c from t1;
create table t3 as select max(a), max(b), max(c) from t1;
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`a` int(11) DEFAULT 5 CHECK (a>10),
`b` int(11) DEFAULT (5+5),
`c` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
show create table t3;
Table Create Table
t3 CREATE TABLE `t3` (
`max(a)` int(11) DEFAULT NULL,
`max(b)` int(11) DEFAULT NULL,
`max(c)` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1, t2, t3;
......@@ -1827,3 +1827,13 @@ alter table t1 alter a set default (2+3), alter b set default 4,
alter table t1 alter a set default 1+2;
show create table t1;
drop table t1;
#
# CREATE ... SELECT
#
create table t1 (a int default 5 check (a>10), b int default (5+5), c int as (a+b));
create table t2 as select a, b, c from t1;
create table t3 as select max(a), max(b), max(c) from t1;
show create table t2;
show create table t3;
drop table t1, t2, t3;
......@@ -10482,8 +10482,8 @@ Column_definition::Column_definition(THD *thd, Field *old_field,
comment= old_field->comment;
decimals= old_field->decimals();
vcol_info= old_field->vcol_info;
default_value= old_field->default_value;
check_constraint= old_field->check_constraint;
default_value= orig_field ? orig_field->default_value : 0;
check_constraint= orig_field ? orig_field->check_constraint : 0;
option_list= old_field->option_list;
switch (sql_type) {
......
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