Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ public boolean requiresAliasForFromQuery() {
return true;
}

/**
* PostgreSQL supports {@code GROUPING SETS}, {@code ROLLUP} and {@code CUBE} since 9.5. A dialect made without a
* connection knows no version and says yes.
*/
@Override
public boolean supportsGroupingSets() {
return dialectVersion.isUnknownOrAtLeast(9, 5);
}

@Override
public boolean supportsCreateOrReplaceTrigger() {
if (org.eclipse.daanse.sql.dialect.api.DialectVersion.UNKNOWN.equals(dialectVersion)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
package org.eclipse.daanse.sql.dialect.db.postgresql;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.sql.Connection;
import java.sql.DatabaseMetaData;

import org.eclipse.daanse.sql.dialect.api.DialectInitData;
import org.eclipse.daanse.sql.jdbc.api.meta.IdentifierInfo;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -74,5 +76,29 @@ void testGenerateRegularExpression_CaseSensitive() throws Exception {
sql);
}

@Test
void testSupportsGroupingSets() {
assertTrue(dialect.supportsGroupingSets(), "a connection without a version is taken as a current PostgreSQL");
assertTrue(dialect.getAggregateCapabilities().groupingSets(),
"the aggregate capabilities carry the same answer");
}

@Test
void testSupportsGroupingSets_FromVersion95() {
assertTrue(withVersion(9, 5).supportsGroupingSets(), "PostgreSQL 9.5 has GROUPING SETS");
assertTrue(withVersion(16, 0).supportsGroupingSets(), "PostgreSQL 16 has GROUPING SETS");
assertFalse(withVersion(9, 4).supportsGroupingSets(), "PostgreSQL 9.4 has no GROUPING SETS");
assertFalse(withVersion(8, 0).supportsGroupingSets(), "PostgreSQL 8.0 has no GROUPING SETS");
}

@Test
void testSupportsGroupingSets_WithoutConnection() {
assertTrue(new PostgreSqlDialect().supportsGroupingSets(), "a dialect without a version says yes");
}

private static PostgreSqlDialect withVersion(int major, int minor) {
return new PostgreSqlDialect(DialectInitData.ansiDefaults().withVersion(major, minor));
}

}
//End PostgreSqlDialectTest.java
Loading