Two questions on recursive queries

30 views
Skip to first unread message

Kenneth McDonald

unread,
Aug 18, 2011, 5:39:06 PM8/18/11
to h2-da...@googlegroups.com
1) How reliable/stable are recursive queries? The page at http://www.h2database.com/html/advanced.html calls support "experimental".

2) Amongst the stated restrictions of recursive queries are,

      All columns of the table expression are of typeVARCHAR

but the examples, especially this one which is very close to what I'd want to do:

CREATE TABLE FOLDER(ID INT PRIMARY KEY, NAME VARCHAR(255), PARENT INT);

INSERT INTO FOLDER VALUES(1, null, null), (2, 'src', 1),
(3, 'main', 2), (4, 'org', 3), (5, 'test', 2);

WITH LINK(ID, NAME, LEVEL) AS (
    SELECT ID, NAME, 0 FROM FOLDER WHERE PARENT IS NULL
    UNION ALL
    SELECT FOLDER.ID, IFNULL(LINK.NAME || '/', '') || FOLDER.NAME, LEVEL + 1
    FROM LINK INNER JOIN FOLDER ON LINK.ID = FOLDER.PARENT
)
SELECT NAME FROM LINK WHERE NAME IS NOT NULL ORDER BY ID;
seem to indicate that INT columns can be used without any problems.

Thanks,
Ken

Thomas Mueller

unread,
Aug 24, 2011, 1:13:08 PM8/24/11
to h2-database
Hi,

> 1) How reliable/stable are recursive queries? The page at http://www.h2database.com/html/advanced.html calls support "experimental".

It is experimental.

> seem to indicate that INT columns can be used without any problems.

Yes, it can be used, but the data type of the result set is varchar.

Regards,
Thomas

Reply all
Reply to author
Forward
0 new messages