@@ -345,6 +345,81 @@ void testWithClauseWithParams() throws Exception {
345345 }
346346 }
347347
348+ @ Test (groups = { "integration" })
349+ void testMultipleWithClauses () throws Exception {
350+ try (Connection conn = getJdbcConnection ();
351+ PreparedStatement stmt = conn .prepareStatement (
352+ "WITH data1 AS (SELECT 1 AS a), " +
353+ " data2 AS (SELECT a + 1 AS b FROM data1) " +
354+ "SELECT * FROM data2" )) {
355+ ResultSet rs = stmt .executeQuery ();
356+ assertTrue (rs .next ());
357+ assertEquals (2 , rs .getInt (1 ));
358+ assertFalse (rs .next ());
359+ }
360+ }
361+
362+ @ Test (groups = { "integration" })
363+ void testRecursiveWithClause () throws Exception {
364+ try (Connection conn = getJdbcConnection ();
365+ PreparedStatement stmt = conn .prepareStatement (
366+ "WITH RECURSIVE numbers AS (" +
367+ " SELECT 1 AS n " +
368+ " UNION ALL " +
369+ " SELECT n + 1 FROM numbers WHERE n < 5" +
370+ ") " +
371+ "SELECT * FROM numbers ORDER BY n" )) {
372+ ResultSet rs = stmt .executeQuery ();
373+ for (int i = 1 ; i <= 5 ; i ++) {
374+ assertTrue (rs .next ());
375+ assertEquals (i , rs .getInt (1 ));
376+ }
377+ assertFalse (rs .next ());
378+ }
379+ }
380+
381+ @ Test (groups = { "integration" })
382+ void testWithClauseWithMultipleParameters () throws Exception {
383+ try (Connection conn = getJdbcConnection ();
384+ PreparedStatement stmt = conn .prepareStatement (
385+ "WITH data AS (" +
386+ " (SELECT number AS n " +
387+ " FROM numbers(?) " +
388+ " WHERE n > ?)" +
389+ ") " +
390+ "SELECT * FROM data WHERE n < ?" )) {
391+ //"WITH data AS ( (SELECT number AS n FROM numbers(?) WHERE n > ?)) SELECT * FROM data WHERE n < ?"
392+ stmt .setInt (1 , 10 ); // numbers(10) = 0-9
393+ stmt .setInt (2 , 3 ); // n > 3
394+ stmt .setInt (3 , 7 ); // n < 7
395+
396+ ResultSet rs = stmt .executeQuery ();
397+ int count = 0 ;
398+ int expected = 4 ; // 4,5,6
399+ while (rs .next ()) {
400+ count ++;
401+ int n = rs .getInt (1 );
402+ assertTrue (n > 3 && n < 7 );
403+ }
404+ assertEquals (3 , count );
405+ }
406+ }
407+
408+ @ Test (groups = { "integration" })
409+ void testSelectFromArray () throws Exception {
410+ try (Connection conn = getJdbcConnection ();
411+ PreparedStatement stmt = conn .prepareStatement (
412+ "SELECT * FROM numbers(?)" )) {
413+ stmt .setInt (1 , 10 ); // numbers(10) = 0-9
414+ ResultSet rs = stmt .executeQuery ();
415+ int count = 0 ;
416+ while (rs .next ()) {
417+ count ++;
418+ }
419+ assertEquals (10 , count );
420+ }
421+ }
422+
348423 @ Test (groups = { "integration" })
349424 void testInsert () throws Exception {
350425 int ROWS = 1000 ;
0 commit comments