You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Compatibility]: expression defaults cannot reference other columns in the same row #28247
createdatabasedefault_colref;
use default_colref;
createtablet(
id intprimary key,
a int,
b int default (a+1)
);
insert into t(id,a) values(1,10);
select*from t;
createtableta(id intprimary key,a int);
insert into ta values(1,10),(2,20);
altertable ta add column b int default (a+1);
-- ERROR 20301: invalid input: ambiguous column reference 'a'
MySQL 8.3.0 行为与组合边界
基础和多级依赖:
createtablet(
id intprimary key,
a int,
b int default (a+1),
c int default (b+1),
key idx_b(b)
);
insert into t(id,a) values(1,10),(2,20);
insert into t(id,a,b,c) values(3,30,default,default);
prepare s from'insert into t(id,a,b,c) values(?,?,default,default)';
set @id=4,@a=40;
execute s using @id,@a;
-- (4,40,41,42)
UPDATE 的语义是按需重新应用默认表达式,而不是普通列变更时自动重算:
update t set a=100where id=1;
-- b,c 仍为 11,12update t set b=default,c=default where id=1;
-- b,c 变为 101,102
CREATE TABLE t2 LIKE t 会保留 b DEFAULT (a+1) 和 c DEFAULT (b+1);向 t2 插入 (id,a)=(10,50) 得到 (10,50,51,52)。
对已有数据增加引用默认值会按每行回填:
createtableta(id intprimary key,a int);
insert into ta values(1,10),(2,20);
altertable ta add column b int default (a+1);
-- rows: (1,10,11), (2,20,21)
MySQL 也允许引用定义位置在后的普通列:
createtabletf(b int default (a+1),a int);
insert into tf(a) values(10),(20);
-- rows: (11,10), (21,20)
Activity
fix: support column references in expression defaults (#28450)
Ariznawlll commentedon Sep 12, 2026
已在最新官方 main
efb2c5084957ac90273a3f625668fc6a784562c4验证。b DEFAULT (a+1)、c DEFAULT (b+1)可引用同一行的前置列。(10,11,12)、(20,21,22)、(30,31,32)。issue_28247_28631_ddl;三轮复跑 12/12 case、252/252 statements 一致通过。测试通过。
fix: support column references in expression defaults (matrixorigin#2…
fix: support column references in expression defaults (matrixorigin#2…
fix: support column references in expression defaults (matrixorigin#2…