datasource-proxy icon indicating copy to clipboard operation
datasource-proxy copied to clipboard

Recursive CTE not recognized as SELECT

Open marschall opened this issue 3 years ago • 1 comments

Recursive CTE are categoried as QueryType.OTHER instead of QueryType.SELECT by QueryUtils. Reproducer

class QueryUtilsTests {

  @Test
  void getQueryType() {
    String sql = "WITH RECURSIVE t(n, level_num) AS (SELECT next value for SEQ_PARENT_ID as n, 1 as level_num UNION ALL SELECT next value for SEQ_PARENT_ID as n, level_num + 1 as level_num  FROM t  WHERE level_num < ?) SELECT n FROM t";
    QueryType queryType = QueryUtils.getQueryType(sql);
    assertSame(QueryType.SELECT, queryType);
  }

}

marschall avatar Oct 22 '21 13:10 marschall

Hi @marschall, Thanks for the report. Admittedly, the current QueryUtils.getQueryType is flawed. I do not intend to provide a full query parser to detect the type, but at least the logic needs to be replaceable by the user. I'll extract the logic to an interface based strategy and allow users to provide own query type detector.

ttddyy avatar Oct 26 '21 05:10 ttddyy