0

I'm really at a loss why I can't get this recursive CTE to work in HANA. We're on HANA 2 so from what I understand it should be supported if I put it in a procedure as SQLSCRIPT. We don't want to use the built in hierarchy functions since we're trying to not use proprietary solutions where possible.

It's not recognizing the nested (INNER JOIN) portion of the CTE. I've tried everything and it says it doesn't find it in my personal schema which is telling me it's interpreting it as a table.

Error:

[Location_In_Repository] Dependent object not found: SqlScript; USERSCHEMA.USER_HIER: symbol not found

BEGIN
WITH USER_HIER AS (
    
SELECT USER_ID, MANAGER_ID
FROM HR.DIM_USER_V

UNION ALL

SELECT hier.USER_ID, hier.MANAGER_ID 
FROM HR.DIM_USER_V hier
    INNER JOIN USER_HIER ON USER_HIER.USER_ID = hier.MANAGER_ID)
SELECT * 
FROM USER_HIER;
END
eshirvana
  • 23,227
  • 3
  • 22
  • 38

1 Answers1

3

The most recent HANA 2 documentation clearly states:

The <with_clause> cannot support recursive query expressions.

The hierarchy functions are the way to go here for HANA. While these are of course proprietary, so are most implementations of recursive SELECTs (see https://www.wikiwand.com/en/Hierarchical_and_recursive_queries_in_SQL).

I'd recommend encapsulating the hierarchy processing into a view or a table function - that way, it is straightforward to exchange the implementation detail when porting to a different DBMS.

Lars Br.
  • 9,949
  • 2
  • 15
  • 29