Package org.hibernate.dialect.function
package org.hibernate.dialect.function
Contains implementations of
SqmFunctionDescriptor
describing a range of relatively-sophisticated SQL functions available in various dialects.-
ClassDescriptionSince the query spec will render a hypothetical set window function instead of an aggregate, the following query transformer will wrap the query spec and apply aggregation in the outer query.Some databases don't have a function like
least()
orgreatest()
, and on those platforms we emulate the function usingcase
.ANSI SQL-inspiredcast()
function, where the target types are enumerated byCastType
, and portability is achieved by delegating toDialect.castPattern(CastType, CastType)
.The HQLstr()
function is now considered a synonym forcast(x as String)
.A chr implementation that translates integer literals to string literals.Enumeratoes common function template definitions.A concat function with a pattern for clob arguments.Recursive CTE based generate_series function.A "function" with no parameters that returns the current date, time, or timestamp.Emulation oftrunc(datetime, temporal_unit)
function that leverages formatting the datetime to string and back to truncate itDB2's varchar_format() can't handle quoted literal strings in the format pattern.DB2's position() function always requires a code unit before version 11.DB2's substring() function requires a code unit and substr() can't optionally take it, so we render substr() by default.A function that dynamically dispatches to other functions, depending on which function validates successfully first.Most databases don't have a function likeevery()
orany()
.ANSI SQL-inspiredextract()
function, where the date/time fields are enumerated byTemporalUnit
, and portability is achieved by delegating toDialect.extractPattern(TemporalUnit)
.A format function with support for composite temporal expressions.AArgumentsValidator
that validates the array type is compatible with the element type.AArgumentsValidator
that validates the array type is compatible with the element type.Standard generate_series function.H2 generate_series function.HANA generate_series function.Emulates the ANSI SQL-standardoverlay()
function usinginsert()
substring()
, andconcat()
.Used in place ofTimestampaddFunction
for databases which don't support fractional seconds in thetimestampadd()
function.A length function with separate patterns for string and clob argument.Emulates the ANSI SQL-standardposition()
function usinglocate()
.HQL function inspired by the ANSI SQL trim function, with a funny syntax involving aTrimSpec
.Most databases don't have a function likeevery()
orany()
.The base for generate_series function implementations that use a static number source.Oracle 8i had nocoalesce()
function, so we emulate it using chainednvl()
s.CustomTruncFunction
for Oracle which uses emulation when truncating datetimes to secondsThe HQLordinal()
function returns the ordinal value of an enumPostgreSQL doesn't support min/max for uuid yet, but since that type is comparable we want to support this operation.CustomTruncFunction
for PostgreSQL which uses the dialect-specific function for numeric truncationPostgreSQL only supports the two-argumenttrunc
andround
functions with the following signatures:trunc(numeric, integer)
round(numeric, integer)
A function to pass through a SQL fragment.CustomTruncFunction
for SQL Server versions before 16, which uses the customSqlServerConvertTruncFunction.DateTruncConvertEmulation
SQL Server doesn't have a function likeevery()
orany()
.SQL Server behaves strangely when the first argument to format is of the type time, so we cast to datetime.SQL Server generate_series function.Simplified API allowing users to contributeSqmFunctionDescriptor
s to HQL.Resolve according to JPA spec 4.8.5Sybase ASE generate_series function.CustomTruncFunction
for Sybase which uses a dialect-specific emulation function for datetimesThetimestampadd()
ordateadd()
function has a funny syntax which accepts aTemporalUnit
as the first argument, and the actual set of accepted units varies widely.Thetimestampdiff()
ordatediff()
function has a funny syntax which accepts aTemporalUnit
as the first argument, and the actual set of accepted units varies widely.A special function that renders a T-SQLstr()
function if more than a single argument is given, or otherwise renders acast()
expression just likeCastStrEmulation
.ANSI SQL-standardtrim()
function, which has a funny syntax involving aTrimSpec
, and portability is achieved usingDialect.trimPattern(TrimSpec, boolean)
.Custom function that manages both numeric and datetime truncation