[#1665] Add support for the empty GROUP BY () clause
This commit is contained in:
parent
c0be23d7c5
commit
e5bbfbe4bf
@ -47,7 +47,6 @@ import static org.jooq.impl.Factory.groupingId;
|
||||
import static org.jooq.impl.Factory.groupingSets;
|
||||
import static org.jooq.impl.Factory.one;
|
||||
import static org.jooq.impl.Factory.rollup;
|
||||
import static org.jooq.impl.Factory.trueCondition;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@ -101,7 +100,7 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T658,
|
||||
assertEquals(1, (int) create().selectOne()
|
||||
.from(TBook())
|
||||
.groupBy()
|
||||
.having(trueCondition())
|
||||
.having("1 = 1")
|
||||
.fetchOne(0, Integer.class));
|
||||
|
||||
// Test a simple group by query
|
||||
|
||||
@ -37,6 +37,11 @@ package org.jooq.impl;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.jooq.SQLDialect.CUBRID;
|
||||
import static org.jooq.SQLDialect.DERBY;
|
||||
import static org.jooq.SQLDialect.HSQLDB;
|
||||
import static org.jooq.SQLDialect.MYSQL;
|
||||
import static org.jooq.SQLDialect.POSTGRES;
|
||||
import static org.jooq.SQLDialect.SQLITE;
|
||||
import static org.jooq.SQLDialect.SQLSERVER;
|
||||
import static org.jooq.impl.Factory.inline;
|
||||
import static org.jooq.impl.Factory.one;
|
||||
@ -511,7 +516,18 @@ implements
|
||||
|
||||
// [#1665] Empty GROUP BY () clauses need parentheses
|
||||
if (getGroupBy().isEmpty()) {
|
||||
context.sql("()");
|
||||
|
||||
// [#1681] TODO: Simulate this for Sybase ASE, Ingres
|
||||
|
||||
// Some dialects don't support empty GROUP BY () clauses
|
||||
if (asList(CUBRID, DERBY, HSQLDB, MYSQL, POSTGRES, SQLITE).contains(context.getDialect())) {
|
||||
context.sql("1");
|
||||
}
|
||||
|
||||
// Few dialects support the SQL standard empty grouping set
|
||||
else {
|
||||
context.sql("()");
|
||||
}
|
||||
}
|
||||
else {
|
||||
context.sql(getGroupBy());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user