diff --git a/jOOQ-manual/src/main/resources/org/jooq/web/grammar-3.11.txt b/jOOQ-manual/src/main/resources/org/jooq/web/grammar-3.11.txt index 75623e4883..8756b74d2e 100644 --- a/jOOQ-manual/src/main/resources/org/jooq/web/grammar-3.11.txt +++ b/jOOQ-manual/src/main/resources/org/jooq/web/grammar-3.11.txt @@ -465,12 +465,17 @@ semiAntiJoin = 'LEFT' ( 'SEMI' | 'ANTI' ) 'JOIN' table joinQualification tableFactor = 'LATERAL' '(' select ')' [ correlationName ] +| tableFunction [ correlationName ] | '(' select ')' [ correlationName ] | values [ correlationName ] | tableName [ versions ] [ correlationName ] [ tableHints ] | '(' table ')' [ correlationName ] ; +tableFunction = + 'GENERATE_SERIES' '(' sum ',' sum [ ',' sum ] ')' +; + tableHints = 'WITH' '(' tableHint { ',' tableHint } ')' ; diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index 8e1cb380c2..135d6c68f8 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -42,6 +42,7 @@ import static org.jooq.Operator.AND; import static org.jooq.Operator.OR; // ... // ... +// ... import static org.jooq.SQLDialect.CUBRID; // ... import static org.jooq.SQLDialect.DERBY; @@ -1768,9 +1769,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -1790,9 +1788,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -1812,9 +1807,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -1834,9 +1826,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -1856,9 +1845,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -1878,9 +1864,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -1900,9 +1883,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -1922,9 +1902,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -1944,9 +1921,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -1966,9 +1940,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -1988,9 +1959,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2010,9 +1978,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2032,9 +1997,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2054,9 +2016,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2076,9 +2035,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2098,9 +2054,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2120,9 +2073,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2142,9 +2092,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2164,9 +2111,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2186,9 +2130,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2208,9 +2149,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2230,9 +2168,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2252,9 +2187,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2274,9 +2206,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2296,9 +2225,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2318,9 +2244,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2340,9 +2263,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2362,9 +2282,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2384,9 +2301,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2406,9 +2320,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2428,9 +2339,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2450,9 +2358,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2472,9 +2377,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2494,9 +2396,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2516,9 +2415,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2538,9 +2434,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2560,9 +2453,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2582,9 +2472,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2604,9 +2491,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2626,9 +2510,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2648,9 +2529,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2670,9 +2548,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2692,9 +2567,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -2714,9 +2586,6 @@ public class DSL { * {@link #with(String, String...)} for strictly non-recursive CTE * and {@link #withRecursive(String, String...)} for strictly * recursive CTE. - *

- * Note that the {@link SQLDialect#H2} database only supports single-table, - * RECURSIVE common table expression lists. */ @Generated("This method was generated using jOOQ-tools") @Support({ FIREBIRD, H2, HSQLDB, POSTGRES }) @@ -8794,6 +8663,158 @@ public class DSL { return new GenerateSeries(nullSafe(from), nullSafe(to)); } + /** + * A table function generating a series of values from from to + * to (inclusive), increasing values by step. + *

+ * This function is inspired by PostgreSQL's + * GENERATE_SERIES(from, to, step) function. Other SQL dialects + * may be capable of emulating this behaviour, e.g. Oracle:

+     * -- PostgreSQL
+     * SELECT * FROM GENERATE_SERIES(a, b, c)
+     *
+     * -- Oracle
+     * SELECT * FROM (SELECT a + LEVEL * c- 1 FROM DUAL CONNECT BY a + LEVEL * c - 1 <= b)
+     * 
+ */ + @Support({ CUBRID, POSTGRES }) + public static Table> generateSeries(int from, int to, int step) { + return generateSeries(val(from), val(to), val(step)); + } + + /** + * A table function generating a series of values from from to + * to (inclusive), increasing values by step. + *

+ * This function is inspired by PostgreSQL's + * GENERATE_SERIES(from, to, step) function. Other SQL dialects may + * be capable of emulating this behaviour, e.g. Oracle:

+     * -- PostgreSQL
+     * SELECT * FROM GENERATE_SERIES(a, b, c)
+     *
+     * -- Oracle
+     * SELECT * FROM (SELECT a + LEVEL * c - 1 FROM DUAL CONNECT BY a + LEVEL * c - 1 <= b)
+     * 
+ */ + @Support({ CUBRID, POSTGRES }) + public static Table> generateSeries(int from, Field to, int step) { + return generateSeries(val(from), nullSafe(to), val(step)); + } + + /** + * A table function generating a series of values from from to + * to (inclusive), increasing values by step. + *

+ * This function is inspired by PostgreSQL's + * GENERATE_SERIES(from, to, step) function. Other SQL dialects may + * be capable of emulating this behaviour, e.g. Oracle:

+     * -- PostgreSQL
+     * SELECT * FROM GENERATE_SERIES(a, b, c)
+     *
+     * -- Oracle
+     * SELECT * FROM (SELECT a + LEVEL * c - 1 FROM DUAL CONNECT BY a + LEVEL * c - 1 <= b)
+     * 
+ */ + @Support({ CUBRID, POSTGRES }) + public static Table> generateSeries(Field from, int to, int step) { + return new GenerateSeries(nullSafe(from), val(to), val(step)); + } + + /** + * A table function generating a series of values from from to + * to (inclusive), increasing values by step. + *

+ * This function is inspired by PostgreSQL's + * GENERATE_SERIES(from, to, step) function. Other SQL dialects may + * be capable of emulating this behaviour, e.g. Oracle:

+     * -- PostgreSQL
+     * SELECT * FROM GENERATE_SERIES(a, b, c)
+     *
+     * -- Oracle
+     * SELECT * FROM (SELECT a + LEVEL * c - 1 FROM DUAL CONNECT BY a + LEVEL * c - 1 <= b)
+     * 
+ */ + @Support({ CUBRID, POSTGRES }) + public static Table> generateSeries(Field from, Field to, int step) { + return new GenerateSeries(nullSafe(from), nullSafe(to), val(step)); + } + + /** + * A table function generating a series of values from from to + * to (inclusive), increasing values by step. + *

+ * This function is inspired by PostgreSQL's + * GENERATE_SERIES(from, to, step) function. Other SQL dialects + * may be capable of emulating this behaviour, e.g. Oracle:

+     * -- PostgreSQL
+     * SELECT * FROM GENERATE_SERIES(a, b, c)
+     *
+     * -- Oracle
+     * SELECT * FROM (SELECT a + LEVEL * c- 1 FROM DUAL CONNECT BY a + LEVEL * c - 1 <= b)
+     * 
+ */ + @Support({ CUBRID, POSTGRES }) + public static Table> generateSeries(int from, int to, Field step) { + return generateSeries(val(from), val(to), nullSafe(step)); + } + + /** + * A table function generating a series of values from from to + * to (inclusive), increasing values by step. + *

+ * This function is inspired by PostgreSQL's + * GENERATE_SERIES(from, to, step) function. Other SQL dialects may + * be capable of emulating this behaviour, e.g. Oracle:

+     * -- PostgreSQL
+     * SELECT * FROM GENERATE_SERIES(a, b, c)
+     *
+     * -- Oracle
+     * SELECT * FROM (SELECT a + LEVEL * c - 1 FROM DUAL CONNECT BY a + LEVEL * c - 1 <= b)
+     * 
+ */ + @Support({ CUBRID, POSTGRES }) + public static Table> generateSeries(int from, Field to, Field step) { + return generateSeries(val(from), nullSafe(to), nullSafe(step)); + } + + /** + * A table function generating a series of values from from to + * to (inclusive), increasing values by step. + *

+ * This function is inspired by PostgreSQL's + * GENERATE_SERIES(from, to, step) function. Other SQL dialects may + * be capable of emulating this behaviour, e.g. Oracle:

+     * -- PostgreSQL
+     * SELECT * FROM GENERATE_SERIES(a, b, c)
+     *
+     * -- Oracle
+     * SELECT * FROM (SELECT a + LEVEL * c - 1 FROM DUAL CONNECT BY a + LEVEL * c - 1 <= b)
+     * 
+ */ + @Support({ CUBRID, POSTGRES }) + public static Table> generateSeries(Field from, int to, Field step) { + return new GenerateSeries(nullSafe(from), val(to), nullSafe(step)); + } + + /** + * A table function generating a series of values from from to + * to (inclusive), increasing values by step. + *

+ * This function is inspired by PostgreSQL's + * GENERATE_SERIES(from, to, step) function. Other SQL dialects may + * be capable of emulating this behaviour, e.g. Oracle:

+     * -- PostgreSQL
+     * SELECT * FROM GENERATE_SERIES(a, b, c)
+     *
+     * -- Oracle
+     * SELECT * FROM (SELECT a + LEVEL * c - 1 FROM DUAL CONNECT BY a + LEVEL * c - 1 <= b)
+     * 
+ */ + @Support({ CUBRID, POSTGRES }) + public static Table> generateSeries(Field from, Field to, Field step) { + return new GenerateSeries(nullSafe(from), nullSafe(to), nullSafe(step)); + } + /** * Create a LATERAL joined table. *

diff --git a/jOOQ/src/main/java/org/jooq/impl/GenerateSeries.java b/jOOQ/src/main/java/org/jooq/impl/GenerateSeries.java index c1d83ac0e2..2633923ed0 100644 --- a/jOOQ/src/main/java/org/jooq/impl/GenerateSeries.java +++ b/jOOQ/src/main/java/org/jooq/impl/GenerateSeries.java @@ -63,12 +63,18 @@ final class GenerateSeries extends AbstractTable> { private final Field from; private final Field to; + private final Field step; GenerateSeries(Field from, Field to) { + this(from, to, null); + } + + GenerateSeries(Field from, Field to, Field step) { super("generate_series"); this.from = from; this.to = to; + this.step = step; } @Override @@ -90,16 +96,26 @@ final class GenerateSeries extends AbstractTable> { // There is a bug in CUBRID preventing reuse of "level" in the // predicate http://jira.cubrid.org/browse/ENGINE-119 - Field level = from.add(level()).sub(one()); - return table("({select} {0} {as} {1} {from} {2} {connect by} {level} <= {3})", - level, - name("generate_series"), - new Dual(), - to.add(one()).sub(from)); + if (step == null) + return table("({select} {0} {as} {1} {from} {2} {connect by} {level} <= {3})", + from.add(level()).sub(one()), + name("generate_series"), + new Dual(), + to.add(one()).sub(from)); + else + return table("({select} {0} {as} {1} {from} {2} {connect by} {level} * {3} <= {4})", + from.add(level().mul(step)).sub(step), + name("generate_series"), + new Dual(), + step, + to.add(step).sub(from)); case POSTGRES: default: - return table("{generate_series}({0}, {1})", from, to); + if (step == null) + return table("{generate_series}({0}, {1})", from, to); + else + return table("{generate_series}({0}, {1}, {2})", from, to, step); } }