I'm trying to create a recursive query with H2, but I can't seem to get it work.
The recursive query I'm trying to get working is something along the lines of the answer from this previous question I posed to StackOverflow. I'm trying to create a query for JUnit testing since H2's inability to create a true stored procedure (Java code dealing with result sets isn't a great answer as it completely skips most of my code under test).
I've thoroughly read the H2 documentation and tried something basic, which is to use one of the examples from the H2 documentation. What I found is that the recursive query shown in the H2 documentation doesn't work when I run it in the console :(
I"m using the second example from the documentation link, which is:
WITH cte1 AS (
SELECT 1 AS FIRST_COLUMN
), cte2 AS (
SELECT FIRST_COLUMN+1 AS FIRST_COLUMN FROM cte1
)
SELECT sum(FIRST_COLUMN) FROM cte2;
Anyone have any idea why this query doesn't work? Seems that if it is in the docs it should work; maybe a regression bug? I'm using H2 version 1.4.188.
Looks like H2 doesn't like that the value from the CTE isn't specified (e.g. cte1(FIRST_COLUMN)
), but the docs seem to show that it isn't required. However, even if I fix that, it fails on the comma after the first CTE's closing parenthesis, which is exactly where I'm stuck with the query I'm trying to write.