提交 34cc207d authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #550 from stumc/Issue#549

Issue#549 Removed UNION ALL requirements for CTE
...@@ -196,13 +196,9 @@ public class ViewIndex extends BaseIndex implements SpatialIndex { ...@@ -196,13 +196,9 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
} }
if (!query.isUnion()) { if (!query.isUnion()) {
throw DbException.get(ErrorCode.SYNTAX_ERROR_2, throw DbException.get(ErrorCode.SYNTAX_ERROR_2,
"recursive queries without UNION ALL"); "recursive queries without UNION");
} }
SelectUnion union = (SelectUnion) query; SelectUnion union = (SelectUnion) query;
if (union.getUnionType() != SelectUnion.UNION_ALL) {
throw DbException.get(ErrorCode.SYNTAX_ERROR_2,
"recursive queries without UNION ALL");
}
Query left = union.getLeft(); Query left = union.getLeft();
// to ensure the last result is not closed // to ensure the last result is not closed
left.disableCache(); left.disableCache();
......
...@@ -29,7 +29,8 @@ public class TestRecursiveQueries extends TestBase { ...@@ -29,7 +29,8 @@ public class TestRecursiveQueries extends TestBase {
@Override @Override
public void test() throws Exception { public void test() throws Exception {
testWrongLinkLargeResult(); testWrongLinkLargeResult();
testSimple(); testSimpleUnionAll();
testSimpleUnion();
} }
private void testWrongLinkLargeResult() throws Exception { private void testWrongLinkLargeResult() throws Exception {
...@@ -60,7 +61,7 @@ public class TestRecursiveQueries extends TestBase { ...@@ -60,7 +61,7 @@ public class TestRecursiveQueries extends TestBase {
deleteDb("recursiveQueries"); deleteDb("recursiveQueries");
} }
private void testSimple() throws Exception { private void testSimpleUnionAll() throws Exception {
deleteDb("recursiveQueries"); deleteDb("recursiveQueries");
Connection conn = getConnection("recursiveQueries"); Connection conn = getConnection("recursiveQueries");
Statement stat; Statement stat;
...@@ -155,5 +156,27 @@ public class TestRecursiveQueries extends TestBase { ...@@ -155,5 +156,27 @@ public class TestRecursiveQueries extends TestBase {
conn.close(); conn.close();
deleteDb("recursiveQueries"); deleteDb("recursiveQueries");
} }
private void testSimpleUnion() throws Exception {
deleteDb("recursiveQueries");
Connection conn = getConnection("recursiveQueries");
Statement stat;
ResultSet rs;
stat = conn.createStatement();
rs = stat.executeQuery("with recursive t(n) as " +
"(select 1 union select n+1 from t where n<3) " +
"select * from t");
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
assertTrue(rs.next());
assertEquals(2, rs.getInt(1));
assertTrue(rs.next());
assertEquals(3, rs.getInt(1));
assertFalse(rs.next());
conn.close();
deleteDb("recursiveQueries");
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论