diff --git a/jOOQ-meta/src/main/java/org/jooq/util/Databases.java b/jOOQ-meta/src/main/java/org/jooq/util/Databases.java index 06853a5e41..b227aa4ee2 100644 --- a/jOOQ-meta/src/main/java/org/jooq/util/Databases.java +++ b/jOOQ-meta/src/main/java/org/jooq/util/Databases.java @@ -110,6 +110,7 @@ public class Databases { case MYSQL: result = MySQLDatabase.class; break; case POSTGRES_9_3: case POSTGRES_9_4: + case POSTGRES_9_5: case POSTGRES: result = PostgresDatabase.class; break; case SQLITE: result = SQLiteDatabase.class; break; diff --git a/jOOQ/src/main/java/org/jooq/SQLDialect.java b/jOOQ/src/main/java/org/jooq/SQLDialect.java index c4c7f24bf6..5979fe2997 100644 --- a/jOOQ/src/main/java/org/jooq/SQLDialect.java +++ b/jOOQ/src/main/java/org/jooq/SQLDialect.java @@ -143,6 +143,15 @@ public enum SQLDialect { */ POSTGRES_9_4("Postgres", false, POSTGRES, POSTGRES_9_3), + /** + * The PostgreSQL dialect family. + *

+ * While this family (and its dialects) have been observed to work to some + * extent on Amazon RedShift as well, we strongly suggest you use the + * official {@link #REDSHIFT} support, instead. + */ + POSTGRES_9_5("Postgres", false, POSTGRES, POSTGRES_9_4), + /** * The SQLite dialect family. */ @@ -528,6 +537,7 @@ public enum SQLDialect { xxxx xxxxxxxxxxxxxx xxxx xxxxxxxxxx xxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxx xxxxxxx xxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + xxxx xxxxxxxx xxxxxx xxxxx xx [/pro] */ case CUBRID: return "org.hibernate.dialect.CUBRIDDialect"; @@ -539,6 +549,7 @@ public enum SQLDialect { case MYSQL: return "org.hibernate.dialect.MySQL5Dialect"; case POSTGRES_9_3: return "org.hibernate.dialect.PostgreSQL92Dialect"; case POSTGRES_9_4: + case POSTGRES_9_5: case POSTGRES: return "org.hibernate.dialect.PostgreSQL94Dialect"; case SQLITE: return null; diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index 6f779ea1c5..c7a6101be0 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -62,6 +62,7 @@ import static org.jooq.SQLDialect.MYSQL; import static org.jooq.SQLDialect.POSTGRES; import static org.jooq.SQLDialect.POSTGRES_9_3; import static org.jooq.SQLDialect.POSTGRES_9_4; +import static org.jooq.SQLDialect.POSTGRES_9_5; // ... import static org.jooq.SQLDialect.SQLITE; // ... @@ -9442,7 +9443,7 @@ public class DSL { } // ------------------------------------------------------------------------ - // XXX Construction of special grouping functions + // XXX Construction of GROUPING SET functions // ------------------------------------------------------------------------ /** @@ -9454,6 +9455,7 @@ public class DSL { *

  • DB2
  • *
  • MySQL (emulated using the GROUP BY .. WITH ROLLUP clause)
  • *
  • Oracle
  • + *
  • PostgreSQL 9.5
  • *
  • SQL Server
  • *
  • Sybase SQL Anywhere
  • * @@ -9468,182 +9470,185 @@ public class DSL { * function * @return A field to be used in a GROUP BY clause */ - @Support({ CUBRID, MARIADB, MYSQL }) + @Support({ CUBRID, MARIADB, MYSQL, POSTGRES_9_5 }) public static GroupField rollup(Field... fields) { return new Rollup(nullSafe(fields)); } - /* [pro] xx - xxx - x xxxxxx x xxxxxxxxxxxx xxxxxxx xxx xxxxxxx xxxxxxxx xxxxxx - x xxx - x xxxx xxx xxxx xxxxxxxx xx xxxx xxxx xxx xxxxxxxxx xxxxxxxxxx - x xxxx - x xxxxxxxxxxxx - x xxxxxxxxxxxxxxx - x xxxxxxx xxxxxxxxxxx - x xxxxxxxxxx xxx xxxxxxxxxxxxx - x xxxxx - x xxx - x xxxxxx xxxxx xxx xxx xxxxxx xxxxxxxxxxxxx xxx x xxxx xxxx xxxxxxxxxxx xx - x xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx xxx xxxxxxxxxxxxxx xxxxxxxxxxx - x xxxxxxx xx xxxxxxxx xxxxxxxxx xx - x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - x - x xxxxxx xxxxxx xxx xxxxxx xxxx xxx xxxx xx xxx xxxxxxxxxxxxxxxxx - x xxxxxxxx - x xxxxxxx x xxxxx xx xx xxxx xx x xxxxxxxxxxx xxxxxxxxx xxxxxx - xx - xxxxxxxxxx xxxx xxxxx xxxxxxx xxxxxxxxxx xxxxxx xx - xxxxxx xxxxxx xxxxxxxxxx xxxxxxxxxxxxxxxx xxxxxxx x - xxxxxx xxxxxxxxxxxxxxxx xxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx - x + /** + * Create a CUBE(field1, field2, .., fieldn) grouping field. + *

    + * This has been observed to work with the following databases: + *

    + *

    + * Please check the SQL Server documentation for a very nice explanation of + * CUBE, ROLLUP, and GROUPING SETS + * clauses in grouping contexts: http://msdn.microsoft.com/en-US/library/bb522495.aspx + * + * @param fields The fields that are part of the CUBE + * function + * @return A field to be used in a GROUP BY clause + */ + @Support({ POSTGRES_9_5 }) + public static GroupField cube(Field... fields) { + return function("cube", Object.class, nullSafe(fields)); + } - xxx - x xxxxxx x xxxxxxxx xxxxxxxxxxxx xxxxxxx xxx xxxxxxx xxxxxxxx xxxxx xxxxx - x xxxx xxxxxxxx xxx xxxx xxxxxxxx xx x xxxxxx xxxxxx - x xxx - x xxxx xxx xxxx xxxxxxxx xx xxxx xxxx xxx xxxxxxxxx xxxxxxxxxx - x xxxx - x xxxxxxxxxxxx - x xxxxxxxxxxxxxxx - x xxxxxxx xxxxxxxxxxx - x xxxxxxxxxx xxx xxxxxxxxxxxxx - x xxxxx - x xxx - x xxxxxx xxxxx xxx xxx xxxxxx xxxxxxxxxxxxx xxx x xxxx xxxx xxxxxxxxxxx xx - x xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx xxx xxxxxxxxxxxxxx xxxxxxxxxxx - x xxxxxxx xx xxxxxxxx xxxxxxxxx xx - x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - x - x xxxxxx xxxxxx xxx xxxxxx xxxx xxx xxxx xx xxx xxxxxxxxxxxxxx xxxxxxxxxxx - x xxxxxxxx - x xxxxxxx x xxxxx xx xx xxxx xx x xxxxxxxxxxx xxxxxxxxx xxxxxx - xx - xxxxxxxxxx xxxx xxxxx xxxxxxx xxxxxxxxxx xxxxxx xx - xxxxxx xxxxxx xxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx x - xxxxxxxxxxxxxxxx xxxxx x xxx xxxxxxxxxxxxxxxxxxxx + /** + * Create a GROUPING SETS(field1, field2, .., fieldn) grouping field where + * each grouping set only consists of a single field. + *

    + * This has been observed to work with the following databases: + *

    + *

    + * Please check the SQL Server documentation for a very nice explanation of + * CUBE, ROLLUP, and GROUPING SETS + * clauses in grouping contexts: http://msdn.microsoft.com/en-US/library/bb522495.aspx + * + * @param fields The fields that are part of the GROUPING SETS + * function + * @return A field to be used in a GROUP BY clause + */ + @Support({ POSTGRES_9_5 }) + public static GroupField groupingSets(Field... fields) { + List>[] array = new List[fields.length]; - xxx xxxx x x xx x x xxxxxxxxxxxxxx xxxx x - xxxxxxxx x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - x + for (int i = 0; i < fields.length; i++) { + array[i] = Arrays.>asList(fields[i]); + } - xxxxxx xxxxxxxxxxxxxxxxxxxx - x + return groupingSets(array); + } - xxx - x xxxxxx x xxxxxxxx xxxxxxxxxxxxxx xxxxxxxxx xxxxxxxxxx xxx xxxxxxxxx - x xxxxxxxxx xxxxxxxx xxxxxx - x xxx - x xxxx xxx xxxx xxxxxxxx xx xxxx xxxx xxx xxxxxxxxx xxxxxxxxxx - x xxxx - x xxxxxxxxxxxx - x xxxxxxxxxxxxxxx - x xxxxxxx xxxxxxxxxxx - x xxxxxxxxxx xxx xxxxxxxxxxxxx - x xxxxx - x xxx - x xxxxxx xxxxx xxx xxx xxxxxx xxxxxxxxxxxxx xxx x xxxx xxxx xxxxxxxxxxx xx - x xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx xxx xxxxxxxxxxxxxx xxxxxxxxxxx - x xxxxxxx xx xxxxxxxx xxxxxxxxx xx - x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - x - x xxxxxx xxxxxxxxx xxx xxxxxx xxxx xxx xxxx xx xxx xxxxxxxxxxxxxx xxxxxxxxxxx - x xxxxxxxx - x xxxxxxx x xxxxx xx xx xxxx xx x xxxxxxxxxxx xxxxxxxxx xxxxxx - xx - xxxxxxxxxx xxxx xxxxx xxxxxxx xxxxxxxxxx xxxxxx xx - xxxxxx xxxxxx xxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxx x - xxxxxxxxxxxxxxxx xxxxx x xxx xxxxxxxxxxxxxxxxxxxxxxx + /** + * Create a GROUPING SETS((field1a, field1b), (field2a), .., (fieldna, + * fieldnb)) grouping field. + *

    + * This has been observed to work with the following databases: + *

    + *

    + * Please check the SQL Server documentation for a very nice explanation of + * CUBE, ROLLUP, and GROUPING SETS + * clauses in grouping contexts: http://msdn.microsoft.com/en-US/library/bb522495.aspx + * + * @param fieldSets The fields that are part of the GROUPING SETS + * function + * @return A field to be used in a GROUP BY clause + */ + @Support({ POSTGRES_9_5 }) + public static GroupField groupingSets(Field[]... fieldSets) { + List>[] array = new List[fieldSets.length]; - xxx xxxx x x xx x x xxxxxxxxxxxxxxxxx xxxx x - xxxxxxxx x xxxxxxxxxxxxxxxxxxxxxxxxxxxx - x + for (int i = 0; i < fieldSets.length; i++) { + array[i] = Arrays.asList(fieldSets[i]); + } - xxxxxx xxxxxxxxxxxxxxxxxxxx - x + return groupingSets(array); + } - xxx - x xxxxxx x xxxxxxxx xxxxxxxxxxxxxx xxxxxxxxx xxxxxxxxxx xxx xxxxxxxxx - x xxxxxxxxx xxxxxxxx xxxxxx - x xxx - x xxxx xxx xxxx xxxxxxxx xx xxxx xxxx xxx xxxxxxxxx xxxxxxxxxx - x xxxx - x xxxxxxxxxxxx - x xxxxxxxxxxxxxxx - x xxxxxxx xxxxxxxxxxx - x xxxxxxxxxx xxx xxxxxxxxxxxxx - x xxxxx - x xxx - x xxxxxx xxxxx xxx xxx xxxxxx xxxxxxxxxxxxx xxx x xxxx xxxx xxxxxxxxxxx xx - x xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx xxx xxxxxxxxxxxxxx xxxxxxxxxxx - x xxxxxxx xx xxxxxxxx xxxxxxxxx xx - x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - x - x xxxxxx xxxxxxxxx xxx xxxxxx xxxx xxx xxxx xx xxx xxxxxxxxxxxxxx xxxxxxxxxxx - x xxxxxxxx - x xxxxxxx x xxxxx xx xx xxxx xx x xxxxxxxxxxx xxxxxxxxx xxxxxx - xx - xxxxxxxxxx xxxx xxxxx xxxxxxx xxxxxxxxxx xxxxxx xx - xxxxxx xxxxxx xxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxx xxxxxxxxxx x - xxxxxxxxxxxxx xxxxx x xxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + /** + * Create a GROUPING SETS((field1a, field1b), (field2a), .., (fieldna, + * fieldnb)) grouping field. + *

    + * This has been observed to work with the following databases: + *

    + *

    + * Please check the SQL Server documentation for a very nice explanation of + * CUBE, ROLLUP, and GROUPING SETS + * clauses in grouping contexts: http://msdn.microsoft.com/en-US/library/bb522495.aspx + * + * @param fieldSets The fields that are part of the GROUPING SETS + * function + * @return A field to be used in a GROUP BY clause + */ + @Support({ POSTGRES_9_5 }) + public static GroupField groupingSets(Collection>... fieldSets) { + WrappedList[] array = new WrappedList[fieldSets.length]; - xxx xxxx x x xx x x xxxxxxxxxxxxxxxxx xxxx x - xxxxxxxx x xxx xxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - x + for (int i = 0; i < fieldSets.length; i++) { + array[i] = new WrappedList(new QueryPartList>(fieldSets[i])); + } - xxxxxx xxx xxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxx xxxxxxxxxxxxxxxxxx xxxxxxx - x + return new Function("grouping sets", SQLDataType.OTHER, array); + } - xxx - x xxxxxx x xxxxxxxxxxxxxxx xxxxxxxxxxx xxxxx xx xx xxxx xxxxx xxxx - x xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx xxx xxxxxxxxxxxxxx xxxxxxxxxxx - x xxxxxxxxxx - x xxx - x xxxx xxx xxxx xxxxxxxx xx xxxx xxxx xxx xxxxxxxxx xxxxxxxxxx - x xxxx - x xxxxxxxxxxxx - x xxxxxxxxxxxxxxx - x xxxxxxx xxxxxxxxxxx - x xxxxxxxxxx xxx xxxxxxxxxxxxx - x xxxxx - x - x xxxxxx xxxxx xxx xxxxxxxx xxxxxxxx - x xxxxxxx xxx xxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxx xxxxx - x xxxx xxxxxxxxxxxxxxx - x xxxx xxxxxxxxxxxxxxxxx - xx - xxxxxxxxxx xxxx xxxxx xxxxxxx xxxxxxxxxx xxxxxx xx - xxxxxx xxxxxx xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx xxxxxx x - xxxxxx xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx - x + /** + * Create a GROUPING(field) aggregation field to be used along with + * CUBE, ROLLUP, and GROUPING SETS + * groupings. + *

    + * This has been observed to work with the following databases: + *

      + *
    • DB2
    • + *
    • Oracle
    • + *
    • PostgreSQL 9.5
    • + *
    • SQL Server
    • + *
    • Sybase SQL Anywhere
    • + *
    + * + * @param field The function argument + * @return The GROUPING aggregation field + * @see #cube(Field...) + * @see #rollup(Field...) + */ + @Support({ POSTGRES_9_5 }) + public static Field grouping(Field field) { + return function("grouping", Integer.class, nullSafe(field)); + } - xxx - x xxxxxx x xxxxxxxxxxxxxxxxxxx xxxxxxx xxx xxxxxxx xxxxxxxxxxx xxxxx xx xx - x xxxx xxxxx xxxx xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx xxx - x xxxxxxxxxxxxxx xxxxxxxxxxx xxxxxxxxxx - x xxx - x xxxx xxx xxxx xxxxxxxx xx xxxx xxxx xxx xxxxxxxxx xxxxxxxxxx - x xxxx - x xxxxxxxxxxxxxxx - x xxxxxxx xxxxxxxxxxx - x xxxxx - x - x xxxxxx xxxxxx xxx xxxxxxxx xxxxxxxxx - x xxxxxxx xxx xxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxx xxxxx - x xxxx xxxxxxxxxxxxxxx - x xxxx xxxxxxxxxxxxxxxxx - xx - xxxxxxxxxx xxxxx xxxxxxx xxxxxxxxxxx - xxxxxx xxxxxx xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxx xxxxxxx x - xxxxxx xxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx - x + /** + * Create a GROUPING_ID(field1, field2, .., fieldn) aggregation field to be + * used along with CUBE, ROLLUP, and + * GROUPING SETS groupings. + *

    + * This has been observed to work with the following databases: + *

      + *
    • Oracle
    • + *
    • SQL Server
    • + *
    + * + * @param fields The function arguments + * @return The GROUPING_ID aggregation field + * @see #cube(Field...) + * @see #rollup(Field...) + */ + @Support({}) + public static Field groupingId(Field... fields) { + return function("grouping_id", Integer.class, nullSafe(fields)); + } - xx [/pro] */ // ------------------------------------------------------------------------ // XXX Bitwise operations // ------------------------------------------------------------------------ diff --git a/jOOQ/src/main/java/org/jooq/impl/Limit.java b/jOOQ/src/main/java/org/jooq/impl/Limit.java index b47b29f663..87ef45fb2c 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Limit.java +++ b/jOOQ/src/main/java/org/jooq/impl/Limit.java @@ -112,6 +112,7 @@ class Limit extends AbstractQueryPart { case POSTGRES: case POSTGRES_9_3: case POSTGRES_9_4: + case POSTGRES_9_5: case SQLITE: { context.castMode(NEVER) .formatSeparator() diff --git a/jOOQ/src/test/java/org/jooq/test/DialectTest.java b/jOOQ/src/test/java/org/jooq/test/DialectTest.java index 72f6eb8d38..9ee654ffaf 100644 --- a/jOOQ/src/test/java/org/jooq/test/DialectTest.java +++ b/jOOQ/src/test/java/org/jooq/test/DialectTest.java @@ -46,6 +46,7 @@ import static org.jooq.SQLDialect.H2; import static org.jooq.SQLDialect.POSTGRES; import static org.jooq.SQLDialect.POSTGRES_9_3; import static org.jooq.SQLDialect.POSTGRES_9_4; +import static org.jooq.SQLDialect.POSTGRES_9_5; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -68,7 +69,8 @@ public class DialectTest extends AbstractTest { assertEquals(POSTGRES_9_3, POSTGRES_9_3.predecessor()); assertEquals(POSTGRES_9_3, POSTGRES_9_4.predecessor()); - assertEquals(POSTGRES_9_4, POSTGRES.predecessor()); + assertEquals(POSTGRES_9_4, POSTGRES_9_5.predecessor()); + assertEquals(POSTGRES_9_5, POSTGRES.predecessor()); } @Test @@ -78,14 +80,17 @@ public class DialectTest extends AbstractTest { assertTrue(POSTGRES_9_3.precedes(POSTGRES_9_3)); assertTrue(POSTGRES_9_3.precedes(POSTGRES_9_4)); + assertTrue(POSTGRES_9_3.precedes(POSTGRES_9_5)); assertTrue(POSTGRES_9_3.precedes(POSTGRES)); assertFalse(POSTGRES_9_4.precedes(POSTGRES_9_3)); assertTrue(POSTGRES_9_4.precedes(POSTGRES_9_4)); + assertTrue(POSTGRES_9_4.precedes(POSTGRES_9_5)); assertTrue(POSTGRES_9_4.precedes(POSTGRES)); assertFalse(POSTGRES.precedes(POSTGRES_9_3)); assertFalse(POSTGRES.precedes(POSTGRES_9_4)); + assertFalse(POSTGRES.precedes(POSTGRES_9_5)); assertTrue(POSTGRES.precedes(POSTGRES)); } }