@@ -2278,6 +2278,77 @@ var InsertScripts = []ScriptTest{
22782278 },
22792279 },
22802280 },
2281+ {
2282+ // https://github.com/dolthub/dolt/issues/9895
2283+ Name : "insert...returning works with after triggers" ,
2284+ Dialect : "mysql" , // actually mariadb
2285+ SetUpScript : []string {
2286+ "create table parent (id int not null auto_increment, primary key (id))" ,
2287+ "create table child(parent_id int not null, version_id int not null auto_increment, primary key (version_id))" ,
2288+ "insert into parent () values ()" ,
2289+ "create trigger trg_child_after_insert after insert on child for each row update parent set id = (id + 1) where id = NEW.parent_id" ,
2290+ },
2291+ Assertions : []ScriptTestAssertion {
2292+ {
2293+ Query : "insert into child (parent_id) values (1) returning version_id" ,
2294+ Expected : []sql.Row {{1 }},
2295+ },
2296+ {
2297+ Query : "select * from parent" ,
2298+ Expected : []sql.Row {{2 }},
2299+ },
2300+ {
2301+ Query : "insert into child (parent_id) values (2) returning version_id" ,
2302+ Expected : []sql.Row {{2 }},
2303+ },
2304+ {
2305+ Query : "select * from parent" ,
2306+ Expected : []sql.Row {{3 }},
2307+ },
2308+ {
2309+ // https://github.com/dolthub/dolt/issues/9907
2310+ Skip : true ,
2311+ Query : "insert into child (parent_id) values ((select id from parent limit 1)) returning parent_id, version_id" ,
2312+ // TODO: update to actual error
2313+ ExpectedErr : nil ,
2314+ },
2315+ },
2316+ },
2317+ {
2318+ Name : "insert...returning works with before triggers" ,
2319+ Dialect : "mysql" , // actually mariadb
2320+ SetUpScript : []string {
2321+ "create table parent (id int not null auto_increment, primary key (id))" ,
2322+ "create table child(parent_id int not null, version_id int not null auto_increment, primary key (version_id))" ,
2323+ "insert into parent () values ()" ,
2324+ "create trigger trg_child_before_insert before insert on child for each row update parent set id = (id + 1) where id = NEW.parent_id" ,
2325+ },
2326+ Assertions : []ScriptTestAssertion {
2327+ {
2328+ Query : "insert into child (parent_id) values (1) returning version_id" ,
2329+ Expected : []sql.Row {{1 }},
2330+ },
2331+ {
2332+ Query : "select * from parent" ,
2333+ Expected : []sql.Row {{2 }},
2334+ },
2335+ {
2336+ Query : "insert into child (parent_id) values (2) returning version_id" ,
2337+ Expected : []sql.Row {{2 }},
2338+ },
2339+ {
2340+ Query : "select * from parent" ,
2341+ Expected : []sql.Row {{3 }},
2342+ },
2343+ {
2344+ //https://github.com/dolthub/dolt/issues/9907
2345+ Skip : true ,
2346+ Query : "insert into child (parent_id) values ((select id from parent limit 1)) returning version_id" ,
2347+ // TODO: update to actual error
2348+ ExpectedErr : nil ,
2349+ },
2350+ },
2351+ },
22812352}
22822353
22832354var InsertDuplicateKeyKeyless = []ScriptTest {
0 commit comments