Package org.h2.expression.function
Class DateTimeFunction
java.lang.Object
org.h2.expression.Expression
org.h2.expression.Operation1_2
org.h2.expression.function.Function1_2
org.h2.expression.function.DateTimeFunction
- All Implemented Interfaces:
NamedExpression,HasSQL,Typed
A date-time function.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final BigDecimalprivate static final BigDecimalprivate static final BigIntegerstatic final intCentury.static final intDATE_TRUNC() (non-standard).static final intDATEADD() (non-standard).static final intDATEDIFF() (non-standard).static final intDay of month.static final intDay of week (locale-specific).static final intDay of year.static final intDecade.static final intDay of week (locale-specific) for PostgreSQL compatibility.static final intEpoch.static final intEXTRACT().private final intprivate static final String[]private static final intprivate final intstatic final intHour.static final intISO day of week.static final intISO week.static final intISO week-based year.static final intMicrosecond.static final intMillennium.static final intMillisecond.static final intMinute.static final intMonth.private static final String[]static final intNanosecond.static final intQuarter.static final intSecond.static final intTime zone hour.static final intTime zone minute.static final intTime zone second.static final intWeek (locale-specific).private static WeekFieldsLocal definitions of day-of-week, week-of-month, and week-of-year.static final intWeek-based year (locale-specific).static final intYear.Fields inherited from class org.h2.expression.Operation1_2
left, right, typeFields inherited from class org.h2.expression.Expression
AUTO_PARENTHESES, MAP_IN_AGGREGATE, MAP_IN_WINDOW, MAP_INITIAL, WITH_PARENTHESES, WITHOUT_PARENTHESESFields inherited from interface org.h2.util.HasSQL
ADD_PLAN_INFORMATION, DEFAULT_SQL_FLAGS, NO_CASTS, QUOTE_ONLY_WHEN_REQUIRED, REPLACE_LOBS_FOR_TRACE, TRACE_SQL_FLAGS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static ValueaddToTimeZone(int field, long count, Value v, int type, long dateValue, long timeNanos) private static ValueaddYearsMonths(int field, boolean years, long count, Value v, int type, long dateValue, long timeNanos) private static intcentury(int year) static Valuedateadd(SessionLocal session, int field, long count, Value v) DATEADD function.private static longdatediff(SessionLocal session, int field, Value v1, Value v2) Calculate the number of crossed unit boundaries between two timestamps.private static intdecade(int year) (package private) static intextractDateTime(SessionLocal session, Value date, int field) private static ValueNumericextractEpoch(SessionLocal session, Value value) private static intextractInteger(SessionLocal session, Value date, int field) Get the specified field of a date, however with years normalized to positive or negative, and month starting with 1.private static intextractInterval(Value date, int field) static intGet date-time field for the specified name.static StringgetFieldName(int field) Get the name of the specified date-time field.private static intgetLocalDayOfWeek(long dateValue) private static intgetLocalWeekOfYear(long dateValue) getName()Get the name.getUnenclosedSQL(StringBuilder builder, int sqlFlags) Get the SQL statement of this expression.getValue(SessionLocal session, Value v1, Value v2) Returns the value of this function.private static WeekFieldsprivate static intmillennium(int year) optimize(SessionLocal session) Try to optimize the expression.private static ValuetruncateDate(SessionLocal session, int field, Value value) Truncate the given date-time value to the specified field.private static longtruncateToWeek(long dateValue, int firstDayOfWeek) private static longtruncateToWeekYear(long dateValue, int firstDayOfWeek, int minimalDaysInFirstWeek) private static longweekdiff(long absolute1, long absolute2, int firstDayOfWeek) Methods inherited from class org.h2.expression.function.Function1_2
getValueMethods inherited from class org.h2.expression.Operation1_2
getCost, getSubexpression, getSubexpressionCount, getType, isEverything, mapColumns, setEvaluatable, updateAggregateMethods inherited from class org.h2.expression.Expression
addFilterConditions, createIndexConditions, getAlias, getBooleanValue, getColumnName, getColumnNameForView, getEnclosedSQL, getNonAliasExpression, getNotIfPossible, getNullable, getSchemaName, getSQL, getSQL, getSQL, getSQL, getTableAlias, getTableName, getWhenSQL, getWhenValue, isConstant, isIdentity, isNullConstant, isValueSet, isWhenConditionOperand, needParentheses, optimizeCondition, toString, writeExpressions, writeExpressionsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.h2.util.HasSQL
getTraceSQL
-
Field Details
-
EXTRACT
public static final int EXTRACTEXTRACT().- See Also:
-
DATE_TRUNC
public static final int DATE_TRUNCDATE_TRUNC() (non-standard).- See Also:
-
DATEADD
public static final int DATEADDDATEADD() (non-standard).- See Also:
-
DATEDIFF
public static final int DATEDIFFDATEDIFF() (non-standard).- See Also:
-
NAMES
-
YEAR
public static final int YEARYear.- See Also:
-
MONTH
public static final int MONTHMonth.- See Also:
-
DAY
public static final int DAYDay of month.- See Also:
-
HOUR
public static final int HOURHour.- See Also:
-
MINUTE
public static final int MINUTEMinute.- See Also:
-
SECOND
public static final int SECONDSecond.- See Also:
-
TIMEZONE_HOUR
public static final int TIMEZONE_HOURTime zone hour.- See Also:
-
TIMEZONE_MINUTE
public static final int TIMEZONE_MINUTETime zone minute.- See Also:
-
TIMEZONE_SECOND
public static final int TIMEZONE_SECONDTime zone second.- See Also:
-
MILLENNIUM
public static final int MILLENNIUMMillennium.- See Also:
-
CENTURY
public static final int CENTURYCentury.- See Also:
-
DECADE
public static final int DECADEDecade.- See Also:
-
QUARTER
public static final int QUARTERQuarter.- See Also:
-
MILLISECOND
public static final int MILLISECONDMillisecond.- See Also:
-
MICROSECOND
public static final int MICROSECONDMicrosecond.- See Also:
-
NANOSECOND
public static final int NANOSECONDNanosecond.- See Also:
-
DAY_OF_YEAR
public static final int DAY_OF_YEARDay of year.- See Also:
-
ISO_DAY_OF_WEEK
public static final int ISO_DAY_OF_WEEKISO day of week.- See Also:
-
ISO_WEEK
public static final int ISO_WEEKISO week.- See Also:
-
ISO_WEEK_YEAR
public static final int ISO_WEEK_YEARISO week-based year.- See Also:
-
DAY_OF_WEEK
public static final int DAY_OF_WEEKDay of week (locale-specific).- See Also:
-
WEEK
public static final int WEEKWeek (locale-specific).- See Also:
-
WEEK_YEAR
public static final int WEEK_YEARWeek-based year (locale-specific).- See Also:
-
EPOCH
public static final int EPOCHEpoch.- See Also:
-
DOW
public static final int DOWDay of week (locale-specific) for PostgreSQL compatibility.- See Also:
-
FIELDS_COUNT
private static final int FIELDS_COUNT- See Also:
-
FIELD_NAMES
-
BD_SECONDS_PER_DAY
-
BI_SECONDS_PER_DAY
-
BD_NANOS_PER_SECOND
-
WEEK_FIELDS
Local definitions of day-of-week, week-of-month, and week-of-year. -
function
private final int function -
field
private final int field
-
-
Constructor Details
-
DateTimeFunction
-
-
Method Details
-
getField
Get date-time field for the specified name.- Parameters:
name- the name- Returns:
- the date-time field
- Throws:
DbException- on unknown field name
-
getFieldName
Get the name of the specified date-time field.- Parameters:
field- the date-time field- Returns:
- the name of the specified field
-
getValue
Description copied from class:Function1_2Returns the value of this function.- Overrides:
getValuein classFunction1_2- Parameters:
session- the sessionv1- the value of first argumentv2- the value of second argument, ornull- Returns:
- the resulting value
-
extractInteger
Get the specified field of a date, however with years normalized to positive or negative, and month starting with 1.- Parameters:
session- the sessiondate- the date valuefield- the field type- Returns:
- the value
-
extractInterval
-
extractDateTime
-
truncateDate
Truncate the given date-time value to the specified field.- Parameters:
session- the sessionfield- the date-time fieldvalue- the date-time value- Returns:
- date the truncated value
-
truncateToWeek
private static long truncateToWeek(long dateValue, int firstDayOfWeek) -
truncateToWeekYear
private static long truncateToWeekYear(long dateValue, int firstDayOfWeek, int minimalDaysInFirstWeek) -
dateadd
DATEADD function.- Parameters:
session- the sessionfield- the date-time fieldcount- count to addv- value to add to- Returns:
- result
-
addYearsMonths
-
addToTimeZone
-
datediff
Calculate the number of crossed unit boundaries between two timestamps. This method is supported for MS SQL Server compatibility.DATEDIFF(YEAR, '2004-12-31', '2005-01-01') = 1
- Parameters:
session- the sessionfield- the date-time fieldv1- the first date-time valuev2- the second date-time value- Returns:
- the number of crossed boundaries
-
weekdiff
private static long weekdiff(long absolute1, long absolute2, int firstDayOfWeek) -
millennium
private static int millennium(int year) -
century
private static int century(int year) -
decade
private static int decade(int year) -
getLocalDayOfWeek
private static int getLocalDayOfWeek(long dateValue) -
getLocalWeekOfYear
private static int getLocalWeekOfYear(long dateValue) -
getWeekFields
-
extractEpoch
-
optimize
Description copied from class:ExpressionTry to optimize the expression.- Specified by:
optimizein classExpression- Parameters:
session- the session- Returns:
- the optimized expression
-
getUnenclosedSQL
Description copied from class:ExpressionGet the SQL statement of this expression. This may not always be the original SQL statement, especially after optimization. Enclosing '(' and ')' are never appended.- Overrides:
getUnenclosedSQLin classFunction1_2- Parameters:
builder- string buildersqlFlags- formatting flags- Returns:
- the specified string builder
-
getName
Description copied from interface:NamedExpressionGet the name.- Returns:
- the name in uppercase
-