mondrian.spi.impl
Class PostgreSqlDialect

java.lang.Object
  extended by mondrian.spi.impl.JdbcDialectImpl
      extended by mondrian.spi.impl.PostgreSqlDialect
All Implemented Interfaces:
Dialect
Direct Known Subclasses:
GreenplumDialect, NetezzaDialect

public class PostgreSqlDialect
extends JdbcDialectImpl

Implementation of Dialect for the PostgreSQL database.

Since:
Nov 23, 2008
Author:
jhyde

Nested Class Summary
 
Nested classes/interfaces inherited from interface mondrian.spi.Dialect
Dialect.DatabaseProduct, Dialect.Datatype
 
Field Summary
static JdbcDialectFactory FACTORY
           
 
Fields inherited from class mondrian.spi.impl.JdbcDialectImpl
databaseProduct, permitsSelectNotInGroupBy, productVersion
 
Constructor Summary
PostgreSqlDialect(Connection connection)
          Creates a PostgreSqlDialect.
 
Method Summary
 boolean allowsRegularExpressionInWhereClause()
          Informs Mondrian if the dialect supports regular expressions when creating the 'where' or the 'having' clause.
protected  String generateOrderByNulls(String expr, boolean ascending, boolean collateNullsLast)
          Generates SQL to force null values to collate last.
 String generateRegularExpression(String source, String javaRegex)
          Must generate a String representing a regular expression match operation between a string literal and a Java regular expression.
 Dialect.DatabaseProduct getDatabaseProduct()
          Returns the database for this Dialect, or Dialect.DatabaseProduct.UNKNOWN if the database is not a common database.
static boolean isGreenplum(DatabaseMetaData databaseMetaData)
          Detects whether this database is Greenplum.
 boolean requiresAliasForFromQuery()
          Returns whether this Dialect requires subqueries in the FROM clause to have an alias.
 
Methods inherited from class mondrian.spi.impl.JdbcDialectImpl
allowsAs, allowsCompoundCountDistinct, allowsCountDistinct, allowsDdl, allowsDialectSharing, allowsFromQuery, allowsJoinOn, allowsMultipleCountDistinct, allowsMultipleDistinctSqlMeasures, allowsOrderByAlias, allowsSelectNotInGroupBy, appendHintsAfterFromClause, caseWhenElse, deduceIdentifierQuoteString, deduceMaxColumnNameLength, deduceProductName, deduceProductVersion, deduceReadOnly, deduceSupportedResultSetStyles, deduceSupportsSelectNotInGroupBy, generateCountExpression, generateInline, generateInlineForAnsi, generateInlineGeneric, generateOrderByNullsAnsi, generateOrderItem, generateOrderItem, getMaxColumnNameLength, getProduct, getQuoteIdentifierString, needsExponent, quote, quoteBooleanLiteral, quoteDateLiteral, quoteDateLiteral, quoteIdentifier, quoteIdentifier, quoteIdentifier, quoteIdentifier, quoteNumericLiteral, quoteStringLiteral, quoteTimeLiteral, quoteTimestampLiteral, requiresGroupByAlias, requiresHavingAlias, requiresOrderByAlias, requiresUnionOrderByExprToBeInSelectClause, requiresUnionOrderByOrdinal, supportsGroupByExpressions, supportsGroupingSets, supportsMultiValueInExpr, supportsResultSetConcurrency, supportsUnlimitedValueList, toString, toUpper
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FACTORY

public static final JdbcDialectFactory FACTORY
Constructor Detail

PostgreSqlDialect

public PostgreSqlDialect(Connection connection)
                  throws SQLException
Creates a PostgreSqlDialect.

Parameters:
connection - Connection
Throws:
SQLException
Method Detail

requiresAliasForFromQuery

public boolean requiresAliasForFromQuery()
Description copied from interface: Dialect
Returns whether this Dialect requires subqueries in the FROM clause to have an alias.

Specified by:
requiresAliasForFromQuery in interface Dialect
Overrides:
requiresAliasForFromQuery in class JdbcDialectImpl
Returns:
whether dialewct requires subqueries to have an alias
See Also:
Dialect.allowsFromQuery()

generateOrderByNulls

protected String generateOrderByNulls(String expr,
                                      boolean ascending,
                                      boolean collateNullsLast)
Description copied from class: JdbcDialectImpl
Generates SQL to force null values to collate last.

This default implementation makes use of the ANSI SQL 1999 CASE-WHEN-THEN-ELSE in conjunction with IS NULL syntax. The resulting SQL will look something like this:

CASE WHEN "expr" IS NULL THEN 0 ELSE 1 END

You can override this method for a particular database to use something more efficient, like ISNULL().

ANSI SQL provides the syntax "ASC/DESC NULLS LAST" and "ASC/DESC NULLS FIRST". If your database supports the ANSI syntax, implement this method by calling JdbcDialectImpl.generateOrderByNullsAnsi(java.lang.String, boolean, boolean).

This method is only called from JdbcDialectImpl.generateOrderItem(String, boolean, boolean, boolean). Some dialects override that method and therefore never call this method.

Overrides:
generateOrderByNulls in class JdbcDialectImpl
Parameters:
expr - Expression.
ascending - Whether ascending.
collateNullsLast - Whether nulls should appear first or last.
Returns:
Expression to force null values to collate last or first.

isGreenplum

public static boolean isGreenplum(DatabaseMetaData databaseMetaData)
Detects whether this database is Greenplum.

Greenplum uses the Postgres driver and appears to be a Postgres instance. The key difference is the presence of 'greenplum' in 'select version()'.

Parameters:
databaseMetaData - Database metadata
Returns:
Whether this is a Greenplum database

getDatabaseProduct

public Dialect.DatabaseProduct getDatabaseProduct()
Description copied from interface: Dialect
Returns the database for this Dialect, or Dialect.DatabaseProduct.UNKNOWN if the database is not a common database.

Specified by:
getDatabaseProduct in interface Dialect
Overrides:
getDatabaseProduct in class JdbcDialectImpl
Returns:
Database

allowsRegularExpressionInWhereClause

public boolean allowsRegularExpressionInWhereClause()
Description copied from interface: Dialect
Informs Mondrian if the dialect supports regular expressions when creating the 'where' or the 'having' clause.

Specified by:
allowsRegularExpressionInWhereClause in interface Dialect
Overrides:
allowsRegularExpressionInWhereClause in class JdbcDialectImpl
Returns:
True if regular expressions are supported.

generateRegularExpression

public String generateRegularExpression(String source,
                                        String javaRegex)
Description copied from interface: Dialect
Must generate a String representing a regular expression match operation between a string literal and a Java regular expression. The string literal might be a column identifier or some other identifier, but the implementation must presume that it is already escaped and fit for use. The regular expression is not escaped and must be adapted to the proper dialect rules.

Postgres / Greenplum example:

generateRegularExpression( "'foodmart'.'customer_name'", "(?i).*oo.*") -> 'foodmart'.'customer_name' ~ "(?i).*oo.*"

Oracle example:

generateRegularExpression( "'foodmart'.'customer_name'", ".*oo.*") -> REGEXP_LIKE('foodmart'.'customer_name', ".*oo.*")

Dialects are allowed to return null if the dialect cannot convert that particular regular expression into something that the database would support.

Specified by:
generateRegularExpression in interface Dialect
Overrides:
generateRegularExpression in class JdbcDialectImpl
Parameters:
source - A String identifying the column to match against.
javaRegex - A Java regular expression to match against.
Returns:
A dialect specific matching operation, or null if the dialect cannot convert that particular regular expression into something that the database would support.

Get Mondrian at SourceForge.net. Fast, secure and free Open Source software downloads