提交 bbd6df54 authored 作者: Thomas Mueller's avatar Thomas Mueller

Subqueries with an aggregate did not always work. Example: select (select…

Subqueries with an aggregate did not always work. Example: select (select count(*) from test where a = t.a and b = 0) from test t group by a
上级 5a84a557
......@@ -217,6 +217,9 @@ public class IndexCursor implements Cursor {
}
public Row get() {
if (cursor == null) {
return null;
}
return cursor.get();
}
......
......@@ -28,6 +28,7 @@ import org.h2.util.StatementBuilder;
import org.h2.util.StringUtils;
import org.h2.value.Value;
import org.h2.value.ValueLong;
import org.h2.value.ValueNull;
/**
* A table filter represents a table that is used in a query. There is one such
......@@ -866,6 +867,9 @@ public class TableFilter implements ColumnResolver {
return v;
}
current = cursor.get();
if (current == null) {
return ValueNull.INSTANCE;
}
}
return current.getValue(columnId);
}
......
......@@ -38,6 +38,7 @@ public class TestCases extends TestBase {
}
public void test() throws Exception {
testGroupSubquery();
testCountDistinctNotNull();
testDependencies();
testConvertType();
......@@ -95,6 +96,19 @@ public class TestCases extends TestBase {
deleteDb("cases");
}
private void testGroupSubquery() throws SQLException {
deleteDb("cases");
Connection conn = getConnection("cases");
Statement stat = conn.createStatement();
stat.execute("create table test(a int, b int)");
stat.execute("create index idx on test(a)");
stat.execute("insert into test values (1, 9), (2, 9), (3, 9)");
ResultSet rs = stat.executeQuery("select (select count(*) from test where a = t.a and b = 0) from test t group by a");
rs.next();
assertEquals(0, rs.getInt(1));
conn.close();
}
private void testCountDistinctNotNull() throws SQLException {
deleteDb("cases");
Connection conn = getConnection("cases");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论