@@ -210,6 +210,10 @@ var ColumnAliasQueries = []ScriptTest{
210210 Query : "SELECT 1 as a, (select a) as b;" ,
211211 Expected : []sql.Row {{1 , 1 }},
212212 },
213+ {
214+ Query : `SELECT 1 as a, (select a union select a) as b;` ,
215+ Expected : []sql.Row {{1 , 1 }},
216+ },
213217 {
214218 Query : "SELECT 1 as a, (select a) as b from dual;" ,
215219 Expected : []sql.Row {{1 , 1 }},
@@ -226,6 +230,22 @@ var ColumnAliasQueries = []ScriptTest{
226230 Query : "SELECT 1 as a, (select a) from xy;" ,
227231 Expected : []sql.Row {{1 , 1 }, {1 , 1 }, {1 , 1 }, {1 , 1 }},
228232 },
233+ {
234+ // https://github.com/dolthub/dolt/issues/4256
235+ Query : `SELECT *, (select i union select i) as a from mytable;` ,
236+ Expected : []sql.Row {
237+ {1 , "first row" , 1 },
238+ {2 , "second row" , 2 },
239+ {3 , "third row" , 3 }},
240+ },
241+ {
242+ Query : "select 1 as b, (select b group by b order by b) order by 1;" ,
243+ Expected : []sql.Row {{1 , 1 }},
244+ },
245+ {
246+ Query : `select 1 as a, (select b), 0 as b;` ,
247+ ExpectedErr : sql .ErrColumnNotFound ,
248+ },
229249 },
230250 },
231251 {
@@ -245,39 +265,15 @@ var ColumnAliasQueries = []ScriptTest{
245265 },
246266 {
247267 Name : "various broken alias queries" ,
268+ Skip : true ,
248269 Assertions : []ScriptTestAssertion {
249- {
250- // The second query in the union subquery returns "x" instead of mytable.i
251- // https://github.com/dolthub/dolt/issues/4256
252- Query : `SELECT *, (select i union select i) as a from mytable;` ,
253- Expected : []sql.Row {
254- {1 , "first row" , 1 },
255- {2 , "second row" , 2 },
256- {3 , "third row" , 3 }},
257- },
258- {
259- Query : `SELECT 1 as a, (select a union select a) as b;` ,
260- Expected : []sql.Row {{1 , 1 }},
261- },
262- {
263- // GMS executes this query, but it is not valid because of the forward ref of alias b.
264- // GMS should return an error about an invalid forward-ref.
265- Skip : true ,
266- Query : `select 1 as a, (select b), 0 as b;` ,
267- ExpectedErr : sql .ErrColumnNotFound ,
268- },
269270 {
270271 // GMS returns "expression 'dt.two' doesn't appear in the group by expressions", but MySQL will execute
271272 // this query.
272273 Query : "select 1 as a, one + 1 as mod1, dt.* from mytable as t1, (select 1, 2 from mytable) as dt (one, two) where dt.one > 0 group by one;" ,
273274 // column names: a, mod1, one, two
274275 Expected : []sql.Row {{1 , 2 , 1 , 2 }},
275276 },
276- {
277- // GMS returns `ambiguous column or alias name "b"` on both cases of `group by b` and `group by 1` inside subquery, but MySQL executes.
278- Query : "select 1 as b, (select b group by b order by b) order by 1;" ,
279- Expected : []sql.Row {{1 , 1 }},
280- },
281277 },
282278 },
283279}
0 commit comments