[jOOQ/jOOQ#10660] Add WITH RECURSIVE emulations for GENERATE_SERIES, where available
This commit is contained in:
parent
d8b16a9c2d
commit
8dbcd7190d
@ -10004,7 +10004,7 @@ public class DSL {
|
||||
* </pre></code>
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, POSTGRES })
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Table<Record1<Integer>> generateSeries(int from, int to) {
|
||||
return generateSeries(val(from), val(to));
|
||||
}
|
||||
@ -10024,7 +10024,7 @@ public class DSL {
|
||||
* </pre></code>
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, POSTGRES })
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Table<Record1<Integer>> generateSeries(int from, Field<Integer> to) {
|
||||
return generateSeries(val(from), nullSafe(to));
|
||||
}
|
||||
@ -10044,7 +10044,7 @@ public class DSL {
|
||||
* </pre></code>
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, POSTGRES })
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Table<Record1<Integer>> generateSeries(Field<Integer> from, int to) {
|
||||
return new GenerateSeries(nullSafe(from), val(to));
|
||||
}
|
||||
@ -10064,7 +10064,7 @@ public class DSL {
|
||||
* </pre></code>
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, POSTGRES })
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Table<Record1<Integer>> generateSeries(Field<Integer> from, Field<Integer> to) {
|
||||
return new GenerateSeries(nullSafe(from), nullSafe(to));
|
||||
}
|
||||
@ -10084,7 +10084,7 @@ public class DSL {
|
||||
* </pre></code>
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, POSTGRES })
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Table<Record1<Integer>> generateSeries(int from, int to, int step) {
|
||||
return generateSeries(val(from), val(to), val(step));
|
||||
}
|
||||
@ -10104,7 +10104,7 @@ public class DSL {
|
||||
* </pre></code>
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, POSTGRES })
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Table<Record1<Integer>> generateSeries(int from, Field<Integer> to, int step) {
|
||||
return generateSeries(val(from), nullSafe(to), val(step));
|
||||
}
|
||||
@ -10124,7 +10124,7 @@ public class DSL {
|
||||
* </pre></code>
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, POSTGRES })
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Table<Record1<Integer>> generateSeries(Field<Integer> from, int to, int step) {
|
||||
return new GenerateSeries(nullSafe(from), val(to), val(step));
|
||||
}
|
||||
@ -10144,7 +10144,7 @@ public class DSL {
|
||||
* </pre></code>
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, POSTGRES })
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Table<Record1<Integer>> generateSeries(Field<Integer> from, Field<Integer> to, int step) {
|
||||
return new GenerateSeries(nullSafe(from), nullSafe(to), val(step));
|
||||
}
|
||||
@ -10164,7 +10164,7 @@ public class DSL {
|
||||
* </pre></code>
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, POSTGRES })
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Table<Record1<Integer>> generateSeries(int from, int to, Field<Integer> step) {
|
||||
return generateSeries(val(from), val(to), nullSafe(step));
|
||||
}
|
||||
@ -10184,7 +10184,7 @@ public class DSL {
|
||||
* </pre></code>
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, POSTGRES })
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Table<Record1<Integer>> generateSeries(int from, Field<Integer> to, Field<Integer> step) {
|
||||
return generateSeries(val(from), nullSafe(to), nullSafe(step));
|
||||
}
|
||||
@ -10204,7 +10204,7 @@ public class DSL {
|
||||
* </pre></code>
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, POSTGRES })
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Table<Record1<Integer>> generateSeries(Field<Integer> from, int to, Field<Integer> step) {
|
||||
return new GenerateSeries(nullSafe(from), val(to), nullSafe(step));
|
||||
}
|
||||
@ -10224,7 +10224,7 @@ public class DSL {
|
||||
* </pre></code>
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, POSTGRES })
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Table<Record1<Integer>> generateSeries(Field<Integer> from, Field<Integer> to, Field<Integer> step) {
|
||||
return new GenerateSeries(nullSafe(from), nullSafe(to), nullSafe(step));
|
||||
}
|
||||
|
||||
@ -37,14 +37,21 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.DSL.inline;
|
||||
// ...
|
||||
import static org.jooq.impl.DSL.one;
|
||||
import static org.jooq.impl.DSL.select;
|
||||
import static org.jooq.impl.DSL.table;
|
||||
import static org.jooq.impl.DSL.unquotedName;
|
||||
import static org.jooq.impl.DSL.withRecursive;
|
||||
import static org.jooq.impl.Names.N_GENERATE_SERIES;
|
||||
import static org.jooq.impl.SQLDataType.INTEGER;
|
||||
import static org.jooq.impl.Tools.visitSubquery;
|
||||
|
||||
import org.jooq.Clause;
|
||||
import org.jooq.Context;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.Name;
|
||||
import org.jooq.Record1;
|
||||
import org.jooq.TableOptions;
|
||||
|
||||
@ -85,6 +92,23 @@ final class GenerateSeries extends AbstractTable<Record1<Integer>> {
|
||||
|
||||
|
||||
|
||||
case FIREBIRD:
|
||||
case HSQLDB:
|
||||
case SQLITE:
|
||||
case MARIADB:
|
||||
case MYSQL: {
|
||||
Name v = unquotedName("v");
|
||||
Field<Integer> f = DSL.field(v, INTEGER);
|
||||
visitSubquery(
|
||||
ctx,
|
||||
withRecursive(N_GENERATE_SERIES, v)
|
||||
.as(select(from).unionAll(select(f.plus(step == null ? inline(1) : step)).from(N_GENERATE_SERIES).where(f.lt(to))))
|
||||
.select(f).from(N_GENERATE_SERIES),
|
||||
true
|
||||
);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -102,12 +126,24 @@ final class GenerateSeries extends AbstractTable<Record1<Integer>> {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
case H2:
|
||||
case POSTGRES:
|
||||
default:
|
||||
default: {
|
||||
if (step == null)
|
||||
ctx.visit(table("{generate_series}({0}, {1})", from, to));
|
||||
else
|
||||
ctx.visit(table("{generate_series}({0}, {1}, {2})", from, to, step));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -53,6 +53,7 @@ import static org.jooq.impl.Keywords.K_NEXTVAL;
|
||||
import static org.jooq.impl.Keywords.K_NEXT_VALUE_FOR;
|
||||
import static org.jooq.impl.Keywords.K_PREVIOUS_VALUE_FOR;
|
||||
import static org.jooq.impl.Names.N_CURRVAL;
|
||||
import static org.jooq.impl.Names.N_GENERATE_SERIES;
|
||||
import static org.jooq.impl.Names.N_GEN_ID;
|
||||
import static org.jooq.impl.Names.N_NEXTVAL;
|
||||
|
||||
@ -186,7 +187,7 @@ public class SequenceImpl<T extends Number> extends AbstractTypedNamed<T> implem
|
||||
|
||||
@Override
|
||||
public final Select<Record1<T>> nextvals(int size) {
|
||||
return DSL.select(nextval()).from(generateSeries(1, size));
|
||||
return DSL.select(nextval()).from(generateSeries(1, size).as(N_GENERATE_SERIES));
|
||||
}
|
||||
|
||||
private enum SequenceMethod {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user