public class

PostgreSQLDialect

extends Dialect
java.lang.Object
   ↳ org.hibernate.dialect.Dialect
     ↳ org.hibernate.dialect.PostgreSQLDialect
Known Direct Subclasses

Class Overview

An SQL dialect for Postgres

For discussion of BLOB support in Postgres, as of 8.4, have a peek at http://jdbc.postgresql.org/documentation/84/binary-data.html. For the effects in regards to Hibernate see http://in.relation.to/15492.lace

Summary

[Expand]
Inherited Constants
From class org.hibernate.dialect.Dialect
Public Constructors
PostgreSQLDialect()
Public Methods
boolean bindLimitParametersInReverseOrder()
ANSI SQL defines the LIMIT clause to be in the form LIMIT offset, limit.
boolean dropConstraints()
Do we need to drop constraints before dropping tables in this dialect?
String getAddColumnString()
The syntax used to add a column to a table (optional).
String getCascadeConstraintsString()
Completely optional cascading drop clause
String getCreateSequenceString(String sequenceName)
Typically dialects which support sequences can create a sequence with a single command.
String getCreateTemporaryTablePostfix()
Get any fragments needing to be postfixed to the command for temporary table creation.
String getCreateTemporaryTableString()
Command used to create a temporary table.
String getCurrentTimestampSelectString()
Retrieve the command used to retrieve the current timestamp from the database.
String getDropSequenceString(String sequenceName)
Typically dialects which support sequences can drop a sequence with a single command.
String getForUpdateString()
Get the string to append to SELECT statements to acquire locks for this dialect.
String getForUpdateString(String aliases)
Get the FOR UPDATE OF column_list fragment appropriate for this dialect given the aliases of the columns to be write locked.
String getIdentityColumnString(int type)
The syntax used during DDL to define a column as being an IDENTITY of a particular type.
String getIdentitySelectString(String table, String column, int type)
Get the select command to use to retrieve the last generated IDENTITY value for a particular table
String getLimitString(String sql, boolean hasOffset)
Apply s limit clause to the query.
Class getNativeIdentifierGeneratorClass()
The class (which implements IdentifierGenerator) which acts as this dialects native generation strategy.
String getNoColumnsInsertString()
The fragment used to insert a row without specifying any column values.
String getQuerySequencesString()
Get the select command used retrieve the names of all sequences.
String getReadLockString(int timeout)
Get the string to append to SELECT statements to acquire WRITE locks for this dialect.
ResultSet getResultSet(CallableStatement ps)
Given a callable statement previously processed by registerResultSetOutParameter(CallableStatement, int), extract the ResultSet from the OUT parameter.
String getSelectClauseNullString(int sqlType)
Workaround for postgres bug #1453
String getSelectSequenceNextValString(String sequenceName)
Generate the select expression fragment that will retrieve the next value of a sequence as part of another (typically DML) statement.
String getSequenceNextValString(String sequenceName)
Generate the appropriate select statement to to retrieve the next value of a sequence.
ViolatedConstraintNameExtracter getViolatedConstraintNameExtracter()
String getWriteLockString(int timeout)
Get the string to append to SELECT statements to acquire WRITE locks for this dialect.
boolean hasDataTypeInIdentityColumn()
Whether this dialect have an Identity clause added to the data type or a completely separate identity data type
boolean isCurrentTimestampSelectStringCallable()
Should the value returned by getCurrentTimestampSelectString() be treated as callable.
int registerResultSetOutParameter(CallableStatement statement, int col)
Registers an OUT parameter which will be returning a ResultSet.
boolean supportsCommentOn()
boolean supportsCurrentTimestampSelection()
Does this dialect support a way to retrieve the database's current timestamp value?
boolean supportsEmptyInList()
Does this dialect support empty IN lists?

For example, is [where XYZ in ()] a supported construct?

boolean supportsExpectedLobUsagePattern()
Expected LOB usage pattern is such that I can perform an insert via prepared statement with a parameter binding for a LOB value without crazy casting to JDBC driver implementation-specific classes...
boolean supportsIdentityColumns()
Does this dialect support identity column key generation?
boolean supportsLimit()
Does this dialect support some form of limiting query results via a SQL clause?
boolean supportsLobValueChangePropogation()
Does the dialect support propagating changes to LOB values back to the database? Talking about mutating the internal value of the locator as opposed to supplying a new locator instance...
boolean supportsOuterJoinForUpdate()
Does this dialect support FOR UPDATE in conjunction with outer joined rows?
boolean supportsPooledSequences()
Does this dialect support "pooled" sequences.
boolean supportsSequences()
Does this dialect support sequences?
boolean supportsTemporaryTables()
Does this dialect support temporary tables?
boolean supportsTupleDistinctCounts()
Does this dialect support `count(distinct a,b)`?
boolean supportsUnboundedLobLocatorMaterialization()
Is it supported to materialize a LOB locator outside the transaction in which it was created?

Again, part of the trickiness here is the fact that this is largely driver dependent.

boolean supportsUnionAll()
Does this dialect support UNION ALL, which is generally a faster variant of UNION?
String toBooleanValueString(boolean bool)
The SQL literal value to which this database maps boolean values.
boolean useInputStreamToInsertBlob()
Should LOBs (both BLOB and CLOB) be bound using stream operations (i.e.
Protected Methods
String getCreateSequenceString(String sequenceName, int initialValue, int incrementSize)
Overloaded form of getCreateSequenceString(String), additionally taking the initial value and increment size to be applied to the sequence definition.
[Expand]
Inherited Methods
From class org.hibernate.dialect.Dialect
From class java.lang.Object

Public Constructors

public PostgreSQLDialect ()

Public Methods

public boolean bindLimitParametersInReverseOrder ()

ANSI SQL defines the LIMIT clause to be in the form LIMIT offset, limit. Does this dialect require us to bind the parameters in reverse order?

Returns
  • true if the correct order is limit, offset

public boolean dropConstraints ()

Do we need to drop constraints before dropping tables in this dialect?

Returns
  • True if constraints must be dropped prior to dropping the table; false otherwise.

public String getAddColumnString ()

The syntax used to add a column to a table (optional).

Returns
  • The "add column" fragment.

public String getCascadeConstraintsString ()

Completely optional cascading drop clause

Returns
  • String

public String getCreateSequenceString (String sequenceName)

Typically dialects which support sequences can create a sequence with a single command. This is convenience form of getCreateSequenceStrings(String) to help facilitate that.

Dialects which support sequences and can create a sequence in a single command need *only* override this method. Dialects which support sequences but require multiple commands to create a sequence should instead override getCreateSequenceStrings(String).

Parameters
sequenceName The name of the sequence
Returns
  • The sequence creation command

public String getCreateTemporaryTablePostfix ()

Get any fragments needing to be postfixed to the command for temporary table creation.

Returns
  • Any required postfix.

public String getCreateTemporaryTableString ()

Command used to create a temporary table.

Returns
  • The command used to create a temporary table.

public String getCurrentTimestampSelectString ()

Retrieve the command used to retrieve the current timestamp from the database.

Returns
  • The command.

public String getDropSequenceString (String sequenceName)

Typically dialects which support sequences can drop a sequence with a single command. This is convenience form of getDropSequenceStrings(String) to help facilitate that.

Dialects which support sequences and can drop a sequence in a single command need *only* override this method. Dialects which support sequences but require multiple commands to drop a sequence should instead override getDropSequenceStrings(String).

Parameters
sequenceName The name of the sequence
Returns
  • The sequence drop commands

public String getForUpdateString ()

Get the string to append to SELECT statements to acquire locks for this dialect.

Returns
  • The appropriate FOR UPDATE clause string.

public String getForUpdateString (String aliases)

Get the FOR UPDATE OF column_list fragment appropriate for this dialect given the aliases of the columns to be write locked.

Parameters
aliases The columns to be write locked.
Returns
  • The appropriate FOR UPDATE OF column_list clause string.

public String getIdentityColumnString (int type)

The syntax used during DDL to define a column as being an IDENTITY of a particular type.

Parameters
type The java.sql.Types type code.
Returns
  • The appropriate DDL fragment.

public String getIdentitySelectString (String table, String column, int type)

Get the select command to use to retrieve the last generated IDENTITY value for a particular table

Parameters
table The table into which the insert was done
column The PK column.
type The java.sql.Types type code.
Returns
  • The appropriate select command

public String getLimitString (String sql, boolean hasOffset)

Apply s limit clause to the query.

Typically dialects utilize variable limit clauses when they support limits. Thus, when building the select command we do not actually need to know the limit or the offest since we will just be using placeholders.

Here we do still pass along whether or not an offset was specified so that dialects not supporting offsets can generate proper exceptions. In general, dialects will override one or the other of this method and getLimitString(String, int, int).

Parameters
sql The query to which to apply the limit.
hasOffset Is the query requesting an offset?
Returns
  • the modified SQL

public Class getNativeIdentifierGeneratorClass ()

The class (which implements IdentifierGenerator) which acts as this dialects native generation strategy.

Comes into play whenever the user specifies the native generator.

Returns
  • The native generator class.

public String getNoColumnsInsertString ()

The fragment used to insert a row without specifying any column values. This is not possible on some databases.

Returns
  • The appropriate empty values clause.

public String getQuerySequencesString ()

Get the select command used retrieve the names of all sequences.

Returns
  • The select command; or null if sequences are not supported.

public String getReadLockString (int timeout)

Get the string to append to SELECT statements to acquire WRITE locks for this dialect. Location of the of the returned string is treated the same as getForUpdateString.

Parameters
timeout in milliseconds, -1 for indefinite wait and 0 for no wait.
Returns
  • The appropriate LOCK clause string.

public ResultSet getResultSet (CallableStatement ps)

Given a callable statement previously processed by registerResultSetOutParameter(CallableStatement, int), extract the ResultSet from the OUT parameter.

Parameters
ps The callable statement.
Returns
  • The extracted result set.
Throws
SQLException

public String getSelectClauseNullString (int sqlType)

Workaround for postgres bug #1453

Parameters
sqlType The java.sql.Types type code.
Returns
  • The appropriate select clause value fragment.

public String getSelectSequenceNextValString (String sequenceName)

Generate the select expression fragment that will retrieve the next value of a sequence as part of another (typically DML) statement.

This differs from getSequenceNextValString(String) in that this should return an expression usable within another statement.

Parameters
sequenceName the name of the sequence
Returns
  • The "nextval" fragment.

public String getSequenceNextValString (String sequenceName)

Generate the appropriate select statement to to retrieve the next value of a sequence.

This should be a "stand alone" select statement.

Parameters
sequenceName the name of the sequence
Returns
  • String The "nextval" select string.

public ViolatedConstraintNameExtracter getViolatedConstraintNameExtracter ()

public String getWriteLockString (int timeout)

Get the string to append to SELECT statements to acquire WRITE locks for this dialect. Location of the of the returned string is treated the same as getForUpdateString.

Parameters
timeout in milliseconds, -1 for indefinite wait and 0 for no wait.
Returns
  • The appropriate LOCK clause string.

public boolean hasDataTypeInIdentityColumn ()

Whether this dialect have an Identity clause added to the data type or a completely separate identity data type

Returns
  • boolean

public boolean isCurrentTimestampSelectStringCallable ()

Should the value returned by getCurrentTimestampSelectString() be treated as callable. Typically this indicates that JDBC escape syntax is being used...

Returns

public int registerResultSetOutParameter (CallableStatement statement, int col)

Registers an OUT parameter which will be returning a ResultSet. How this is accomplished varies greatly from DB to DB, hence its inclusion (along with getResultSet(CallableStatement)) here.

Parameters
statement The callable statement.
col The bind position at which to register the OUT param.
Returns
  • The number of (contiguous) bind positions used.
Throws
SQLException

public boolean supportsCommentOn ()

public boolean supportsCurrentTimestampSelection ()

Does this dialect support a way to retrieve the database's current timestamp value?

Returns
  • True if the current timestamp can be retrieved; false otherwise.

public boolean supportsEmptyInList ()

Does this dialect support empty IN lists?

For example, is [where XYZ in ()] a supported construct?

Returns
  • True if empty in lists are supported; false otherwise.

public boolean supportsExpectedLobUsagePattern ()

Expected LOB usage pattern is such that I can perform an insert via prepared statement with a parameter binding for a LOB value without crazy casting to JDBC driver implementation-specific classes...

Part of the trickiness here is the fact that this is largely driver dependent. For example, Oracle (which is notoriously bad with LOB support in their drivers historically) actually does a pretty good job with LOB support as of the 10.2.x versions of their drivers...

Returns
  • True if normal LOB usage patterns can be used with this driver; false if driver-specific hookiness needs to be applied.

public boolean supportsIdentityColumns ()

Does this dialect support identity column key generation?

Returns
  • True if IDENTITY columns are supported; false otherwise.

public boolean supportsLimit ()

Does this dialect support some form of limiting query results via a SQL clause?

Returns
  • True if this dialect supports some form of LIMIT.

public boolean supportsLobValueChangePropogation ()

Does the dialect support propagating changes to LOB values back to the database? Talking about mutating the internal value of the locator as opposed to supplying a new locator instance...

For BLOBs, the internal value might be changed by: setBinaryStream(long), setBytes(long, byte[]), setBytes(long, byte[], int, int), or truncate(long).

For CLOBs, the internal value might be changed by: setAsciiStream(long), setCharacterStream(long), setString(long, String), setString(long, String, int, int), or truncate(long).

NOTE : I do not know the correct answer currently for databases which (1) are not part of the cruise control process or (2) do not supportsExpectedLobUsagePattern().

Returns
  • True if the changes are propagated back to the database; false otherwise.

public boolean supportsOuterJoinForUpdate ()

Does this dialect support FOR UPDATE in conjunction with outer joined rows?

Returns
  • True if outer joined rows can be locked via FOR UPDATE.

public boolean supportsPooledSequences ()

Does this dialect support "pooled" sequences. Not aware of a better name for this. Essentially can we specify the initial and increment values?

Returns
  • True if such "pooled" sequences are supported; false otherwise.

public boolean supportsSequences ()

Does this dialect support sequences?

Returns
  • True if sequences supported; false otherwise.

public boolean supportsTemporaryTables ()

Does this dialect support temporary tables?

Returns
  • True if temp tables are supported; false otherwise.

public boolean supportsTupleDistinctCounts ()

Does this dialect support `count(distinct a,b)`?

Returns
  • True if the database supports counting disintct tuples; false otherwise.

public boolean supportsUnboundedLobLocatorMaterialization ()

Is it supported to materialize a LOB locator outside the transaction in which it was created?

Again, part of the trickiness here is the fact that this is largely driver dependent.

NOTE: all database I have tested which supportsExpectedLobUsagePattern() also support the ability to materialize a LOB outside the owning transaction...

Returns
  • True if unbounded materialization is supported; false otherwise.

public boolean supportsUnionAll ()

Does this dialect support UNION ALL, which is generally a faster variant of UNION?

Returns
  • True if UNION ALL is supported; false otherwise.

public String toBooleanValueString (boolean bool)

The SQL literal value to which this database maps boolean values.

Parameters
bool The boolean value
Returns
  • The appropriate SQL literal.

public boolean useInputStreamToInsertBlob ()

Should LOBs (both BLOB and CLOB) be bound using stream operations (i.e. setBinaryStream(int, InputStream)).

Returns
  • True if BLOBs and CLOBs should be bound using stream operations.

Protected Methods

protected String getCreateSequenceString (String sequenceName, int initialValue, int incrementSize)

Overloaded form of getCreateSequenceString(String), additionally taking the initial value and increment size to be applied to the sequence definition.

The default definition is to suffix getCreateSequenceString(String) with the string: " start with {initialValue} increment by {incrementSize}" where {initialValue} and {incrementSize} are replacement placeholders. Generally dialects should only need to override this method if different key phrases are used to apply the allocation information.

Parameters
sequenceName The name of the sequence
initialValue The initial value to apply to 'create sequence' statement
incrementSize The increment value to apply to 'create sequence' statement
Returns
  • The sequence creation command