@@ -95,6 +95,47 @@ var GeneratedColumnTests = []ScriptTest{
95
95
},
96
96
},
97
97
},
98
+ {
99
+ Name : "generated column with DEFAULT in UPDATE clause (issue #9438)" ,
100
+ SetUpScript : []string {
101
+ "create table t (i int primary key, j int generated always as (i + 10))" ,
102
+ "insert into t (i) values (1), (2), (3)" ,
103
+ },
104
+ Assertions : []ScriptTestAssertion {
105
+ {
106
+ Query : "select * from t order by i" ,
107
+ Expected : []sql.Row {{1 , 11 }, {2 , 12 }, {3 , 13 }},
108
+ },
109
+ {
110
+ Query : "update t set j = default" ,
111
+ Expected : []sql.Row {{NewUpdateResult (3 , 0 )}}, // 3 rows matched, 0 changed (values already correct)
112
+ },
113
+ {
114
+ Query : "select * from t order by i" ,
115
+ Expected : []sql.Row {{1 , 11 }, {2 , 12 }, {3 , 13 }}, // Values should remain the same
116
+ },
117
+ {
118
+ Query : "update t set i = 5 where i = 1" , // This should update both i and j (through generation)
119
+ Expected : []sql.Row {{NewUpdateResult (1 , 1 )}},
120
+ },
121
+ {
122
+ Query : "select * from t order by i" ,
123
+ Expected : []sql.Row {{2 , 12 }, {3 , 13 }, {5 , 15 }}, // j should be updated to i + 10 = 15
124
+ },
125
+ {
126
+ Query : "update t set j = default where i = 5" , // Explicit DEFAULT on specific row
127
+ Expected : []sql.Row {{NewUpdateResult (1 , 0 )}}, // 1 row matched, 0 changed (value already correct)
128
+ },
129
+ {
130
+ Query : "select * from t where i = 5" ,
131
+ Expected : []sql.Row {{5 , 15 }}, // Value should still be correct
132
+ },
133
+ {
134
+ Query : "update t set j = 99" , // Should still fail for non-DEFAULT values
135
+ ExpectedErr : sql .ErrGeneratedColumnValue ,
136
+ },
137
+ },
138
+ },
98
139
{
99
140
Name : "generated column with DEFAULT in VALUES clause (issue #9428)" ,
100
141
SetUpScript : []string {
0 commit comments