mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
MDEV-25403 ALTER TABLE wrongly checks for field's default value if AFTER is used
When a column is added to an non-empty table, existing rows will have a column's default value for existing rows. Or a "zero value" if the column has no default. But this check should be skipped when an existing column is altered.
This commit is contained in:
@ -2517,5 +2517,22 @@ ALTER TABLE t1 ALTER COLUMN k1 SET DEFAULT (SELECT 1 FROM t2 limit 1);
|
|||||||
ERROR HY000: Function or expression 'select ...' cannot be used in the DEFAULT clause of `k1`
|
ERROR HY000: Function or expression 'select ...' cannot be used in the DEFAULT clause of `k1`
|
||||||
DROP TABLE t1,t2;
|
DROP TABLE t1,t2;
|
||||||
#
|
#
|
||||||
|
# MDEV-25403 ALTER TABLE wrongly checks for field's default value if AFTER is used
|
||||||
|
#
|
||||||
|
create table t1(t int, d date not null);
|
||||||
|
insert into t1 values (1,'2001-1-1');
|
||||||
|
set sql_mode = "no_zero_date";
|
||||||
|
alter table t1 change d d date not null after t, add i int;
|
||||||
|
show create table t1;
|
||||||
|
Table Create Table
|
||||||
|
t1 CREATE TABLE `t1` (
|
||||||
|
`t` int(11) DEFAULT NULL,
|
||||||
|
`d` date NOT NULL,
|
||||||
|
`i` int(11) DEFAULT NULL
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1
|
||||||
|
alter table t1 add x date not null;
|
||||||
|
ERROR 22007: Incorrect date value: '0000-00-00' for column `test`.`t1`.`x` at row 1
|
||||||
|
drop table t1;
|
||||||
|
#
|
||||||
# End of 10.2 tests
|
# End of 10.2 tests
|
||||||
#
|
#
|
||||||
|
@ -2044,6 +2044,18 @@ CREATE TABLE t2 (i1 int);
|
|||||||
ALTER TABLE t1 ALTER COLUMN k1 SET DEFAULT (SELECT 1 FROM t2 limit 1);
|
ALTER TABLE t1 ALTER COLUMN k1 SET DEFAULT (SELECT 1 FROM t2 limit 1);
|
||||||
DROP TABLE t1,t2;
|
DROP TABLE t1,t2;
|
||||||
|
|
||||||
|
--echo #
|
||||||
|
--echo # MDEV-25403 ALTER TABLE wrongly checks for field's default value if AFTER is used
|
||||||
|
--echo #
|
||||||
|
create table t1(t int, d date not null);
|
||||||
|
insert into t1 values (1,'2001-1-1');
|
||||||
|
set sql_mode = "no_zero_date";
|
||||||
|
alter table t1 change d d date not null after t, add i int;
|
||||||
|
show create table t1;
|
||||||
|
--error ER_TRUNCATED_WRONG_VALUE
|
||||||
|
alter table t1 add x date not null;
|
||||||
|
drop table t1;
|
||||||
|
|
||||||
--echo #
|
--echo #
|
||||||
--echo # End of 10.2 tests
|
--echo # End of 10.2 tests
|
||||||
--echo #
|
--echo #
|
||||||
|
@ -7906,7 +7906,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
|
|||||||
def->sql_type == MYSQL_TYPE_NEWDATE ||
|
def->sql_type == MYSQL_TYPE_NEWDATE ||
|
||||||
def->sql_type == MYSQL_TYPE_DATETIME ||
|
def->sql_type == MYSQL_TYPE_DATETIME ||
|
||||||
def->sql_type == MYSQL_TYPE_DATETIME2) &&
|
def->sql_type == MYSQL_TYPE_DATETIME2) &&
|
||||||
!alter_ctx->datetime_field &&
|
!alter_ctx->datetime_field && !def->field &&
|
||||||
!(~def->flags & (NO_DEFAULT_VALUE_FLAG | NOT_NULL_FLAG)) &&
|
!(~def->flags & (NO_DEFAULT_VALUE_FLAG | NOT_NULL_FLAG)) &&
|
||||||
thd->variables.sql_mode & MODE_NO_ZERO_DATE)
|
thd->variables.sql_mode & MODE_NO_ZERO_DATE)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user