Currently using Oracle for production and H2 for local. Oracle throws an error when a WITH ANCESTORS
is used but H2 continues on indefinitely. I want to make an agnostic query that fails in both, or at the very least can check if a loop occurs.
WITH ANCESTORS (ID, SUPERVISOR_ID) AS
(SELECT ID, SUPERVISOR_ID
FROM EMPLOYEE
WHERE ID = :id
UNION ALL
SELECT E2.ID, E2.SUPERVISOR_ID
FROM ANCESTORS E1
JOIN EMPLOYEE E2 ON E1.SUPERVISOR_ID = E2.ID)
SELECT ID, SUPERVISOR_ID
FROM ANCESTORS;
Employee
ID | SUPERVISOR_ID
1 | 2
2 | 3
3 | 4
4 | 1
This throws a nice error in oracle, thus works properly in prod, but not so much in H2 for development.