Class PostgresqlSqlDialect

java.lang.Object
org.apache.calcite.sql.SqlDialect
org.apache.calcite.sql.dialect.PostgresqlSqlDialect

public class PostgresqlSqlDialect extends SqlDialect
A SqlDialect implementation for the PostgreSQL database.
  • Field Details

    • POSTGRESQL_TYPE_SYSTEM

      public static final RelDataTypeSystem POSTGRESQL_TYPE_SYSTEM
      PostgreSQL type system.
    • DEFAULT_CONTEXT

      public static final SqlDialect.Context DEFAULT_CONTEXT
    • DEFAULT

      public static final SqlDialect DEFAULT
  • Constructor Details

    • PostgresqlSqlDialect

      public PostgresqlSqlDialect(SqlDialect.Context context)
      Creates a PostgresqlSqlDialect.
  • Method Details

    • supportsCharSet

      public boolean supportsCharSet()
      Description copied from class: SqlDialect
      Returns whether the dialect supports character set names as part of a data type, for instance VARCHAR(30) CHARACTER SET `ISO-8859-1`.
      Overrides:
      supportsCharSet in class SqlDialect
    • getCastSpec

      public @Nullable SqlNode getCastSpec(RelDataType type)
      Description copied from class: SqlDialect
      Returns SqlNode for type in "cast(column as type)", which might be different between databases by type name, precision etc.

      If this method returns null, the cast will be omitted. In the default implementation, this is the case for the NULL type, and therefore CAST(NULL AS <nulltype>) is rendered as NULL.

      Overrides:
      getCastSpec in class SqlDialect
    • rewriteSingleValueExpr

      public SqlNode rewriteSingleValueExpr(SqlNode aggCall, RelDataType relDataType)
      Description copied from class: SqlDialect
      Rewrites SINGLE_VALUE into expression based on database variants E.g. HSQLDB, MYSQL, ORACLE, etc.
      Overrides:
      rewriteSingleValueExpr in class SqlDialect
    • supportsFunction

      public boolean supportsFunction(SqlOperator operator, RelDataType type, List<RelDataType> paramTypes)
      Description copied from class: SqlDialect
      Returns whether this dialect supports a given function or operator. It only applies to built-in scalar functions and operators, since user-defined functions and procedures should be read by JdbcSchema.
      Overrides:
      supportsFunction in class SqlDialect
    • requiresAliasForFromItems

      public boolean requiresAliasForFromItems()
      Description copied from class: SqlDialect
      Whether a sub-query in the FROM clause must have an alias.

      For example, in PostgreSQL, this query is legal:

      SELECT * FROM (SELECT * FROM Emp) As e

      but remove the alias e and it is not:

      SELECT * FROM (SELECT * FROM Emp)

      In Oracle, both queries are legal.

      Overrides:
      requiresAliasForFromItems in class SqlDialect
    • supportsNestedAggregations

      public boolean supportsNestedAggregations()
      Description copied from class: SqlDialect
      Returns whether the dialect supports nested aggregations, for instance SELECT SUM(SUM(1)) .
      Overrides:
      supportsNestedAggregations in class SqlDialect
    • unparseCall

      public void unparseCall(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec)
      Overrides:
      unparseCall in class SqlDialect
    • rewriteMaxMinExpr

      public SqlNode rewriteMaxMinExpr(SqlNode aggCall, RelDataType relDataType)
      Description copied from class: SqlDialect
      Rewrites MAX(x)/MIN(x) as BOOL_OR(x)/BOOL_AND(x) for certain database variants (Postgres and Redshift, currently).
      Overrides:
      rewriteMaxMinExpr in class SqlDialect
      See Also:
    • supportsGroupByLiteral

      public boolean supportsGroupByLiteral()
      Description copied from class: SqlDialect
      Returns whether the dialect supports GROUP BY literals.

      For instance, in SqlDialect.DatabaseProduct.REDSHIFT, the following queries are illegal:

      
       select avg(salary)
       from emp
       group by true
      
       select avg(salary)
       from emp
       group by 'a', DATE '2022-01-01'
       
      Overrides:
      supportsGroupByLiteral in class SqlDialect