提交 695c4a99 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add LOCALTIMESTAMP function from the SQL standard

上级 f651bc69
......@@ -3953,18 +3953,30 @@ CURRENT_TIME()
"
"Functions (Time and Date)","CURRENT_TIMESTAMP","
{ CURRENT_TIMESTAMP [ ( [ int ] ) ] | NOW( [ int ] ) }
CURRENT_TIMESTAMP [ ( [ int ] ) ]
","
Returns the current timestamp with time zone.
Time zone offset is set to a current time zone offset
If fractional seconds precision is specified it should be from 0 to 9, 9 is default.
The specified value can be used only to limit precision of a result.
The actual maximum available precision depends on operating system and JVM and can be 3 (milliseconds) or higher.
Higher precision is not available before Java 9.
This method always returns the same value within a transaction.
","
CURRENT_TIMESTAMP()
"
"Functions (Time and Date)","LOCALTIMESTAMP","
{ LOCALTIMESTAMP [ ( [ int ] ) ] | NOW( [ int ] ) }
","
Returns the current timestamp.
If fractional seconds precision is specified it should be from 0 to 9, 9 is default.
The specified value can be used only to limit precision of a result.
The actual maximum available precision depends on operating system and JVM and can be 3 (milliseconds) or higher.
Higher precision is not available before Java 9.
CURRENT_TIMESTAMP returns timestamp with time zone, its time zone offset is set to a current time zone offset.
NOW() returns the local timestamp without time zone information.
These methods always return the same value within a transaction.
","
CURRENT_TIMESTAMP()
LOCALTIMESTAMP()
"
"Functions (Time and Date)","DATEADD","
......
......@@ -504,8 +504,8 @@ unless they are quoted (surrounded with double quotes). The list is currently:
<code>
ALL, CHECK, CONSTRAINT, CROSS, CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP, DISTINCT, EXCEPT,
EXISTS, FALSE, FETCH, FOR, FOREIGN, FROM, FULL, GROUP, HAVING, INNER, INTERSECT, INTERSECTS,
IS, JOIN, LIKE, LIMIT, MINUS, NATURAL, NOT, NULL, OFFSET, ON, ORDER, PRIMARY, ROWNUM, SELECT,
SYSDATE, SYSTIME, SYSTIMESTAMP, TODAY, TOP, TRUE, UNION, UNIQUE, WHERE, WITH
IS, JOIN, LIKE, LIMIT, LOCALTIMESTAMP, MINUS, NATURAL, NOT, NULL, OFFSET, ON, ORDER, PRIMARY,
ROWNUM, SELECT, SYSDATE, SYSTIME, SYSTIMESTAMP, TODAY, TOP, TRUE, UNION, UNIQUE, WHERE, WITH
</code>
</p><p>
Certain words of this list are keywords because they are functions that can be used without '()' for compatibility,
......
......@@ -3148,6 +3148,8 @@ public class Parser {
r = readFunctionWithoutParameters("USER");
} else if (equalsToken("CURRENT_TIMESTAMP", name)) {
r = readFunctionWithoutParameters("CURRENT_TIMESTAMP");
} else if (equalsToken("LOCALTIMESTAMP", name)) {
r = readFunctionWithoutParameters("LOCALTIMESTAMP");
} else if (equalsToken("SYSDATE", name)) {
r = readFunctionWithoutParameters("CURRENT_TIMESTAMP");
} else if (equalsToken("SYSTIMESTAMP", name)) {
......
......@@ -97,7 +97,7 @@ public class Function extends Expression implements FunctionCall {
public static final int CURDATE = 100, CURTIME = 101, DATE_ADD = 102,
DATE_DIFF = 103, DAY_NAME = 104, DAY_OF_MONTH = 105,
DAY_OF_WEEK = 106, DAY_OF_YEAR = 107, HOUR = 108, MINUTE = 109,
MONTH = 110, MONTH_NAME = 111, NOW = 112, QUARTER = 113,
MONTH = 110, MONTH_NAME = 111, LOCALTIMESTAMP = 112, QUARTER = 113,
SECOND = 114, WEEK = 115, YEAR = 116, CURRENT_DATE = 117,
CURRENT_TIME = 118, CURRENT_TIMESTAMP = 119, EXTRACT = 120,
FORMATDATETIME = 121, PARSEDATETIME = 122, ISO_YEAR = 123,
......@@ -304,7 +304,9 @@ public class Function extends Expression implements FunctionCall {
VAR_ARGS, Value.TIMESTAMP_TZ);
addFunctionNotDeterministic("SYSTIMESTAMP", CURRENT_TIMESTAMP,
VAR_ARGS, Value.TIMESTAMP_TZ);
addFunctionNotDeterministic("NOW", NOW,
addFunctionNotDeterministic("LOCALTIMESTAMP", LOCALTIMESTAMP,
VAR_ARGS, Value.TIMESTAMP);
addFunctionNotDeterministic("NOW", LOCALTIMESTAMP,
VAR_ARGS, Value.TIMESTAMP);
addFunction("DATEADD", DATE_ADD,
3, Value.TIMESTAMP);
......@@ -830,7 +832,7 @@ public class Function extends Expression implements FunctionCall {
result = session.getTransactionStart().convertTo(Value.TIME);
break;
}
case NOW: {
case LOCALTIMESTAMP: {
Value vt = session.getTransactionStart().convertTo(Value.TIMESTAMP);
result = v0 == null ? vt : vt.convertScale(false, v0.getInt());
break;
......@@ -2060,7 +2062,7 @@ public class Function extends Expression implements FunctionCall {
case GREATEST:
min = 1;
break;
case NOW:
case LOCALTIMESTAMP:
case CURRENT_TIMESTAMP:
case RAND:
max = 1;
......
......@@ -1545,9 +1545,9 @@ public class JdbcDatabaseMetaData extends TraceObject implements
* <pre>
* ALL, CHECK, CONSTRAINT, CROSS, CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP,
* DISTINCT, EXCEPT, EXISTS, FALSE, FETCH, FOR, FOREIGN, FROM, FULL, GROUP,
* HAVING, INNER, INTERSECT, INTERSECTS, IS, JOIN, LIKE, LIMIT, MINUS, NATURAL,
* NOT, NULL, OFFSET, ON, ORDER, PRIMARY, ROWNUM, SELECT, SYSDATE, SYSTIME,
* SYSTIMESTAMP, TODAY, TOP, TRUE, UNION, UNIQUE, WHERE, WITH
* HAVING, INNER, INTERSECT, INTERSECTS, IS, JOIN, LIKE, LIMIT, LOCALTIMESTAMP,
* MINUS, NATURAL, NOT, NULL, OFFSET, ON, ORDER, PRIMARY, ROWNUM, SELECT, SYSDATE,
* SYSTIME, SYSTIMESTAMP, TODAY, TOP, TRUE, UNION, UNIQUE, WHERE, WITH
* </pre>
*
* @return a list of additional the keywords
......
......@@ -147,10 +147,15 @@ public class ParserUtil {
case 'J':
return getKeywordOrIdentifier(s, "JOIN", KEYWORD);
case 'L':
if ("LIMIT".equals(s)) {
if ("LIMIT".equals(s) || "LIKE".equals(s)) {
return KEYWORD;
}
return getKeywordOrIdentifier(s, "LIKE", KEYWORD);
if (additionalKeywords) {
if ("LOCALTIMESTAMP".equals(s)) {
return KEYWORD;
}
}
return IDENTIFIER;
case 'M':
return getKeywordOrIdentifier(s, "MINUS", KEYWORD);
case 'N':
......
......@@ -2,3 +2,9 @@
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
SELECT CAST(CURRENT_TIMESTAMP AS TIMESTAMP) = LOCALTIMESTAMP;
>> TRUE
SELECT CAST(CURRENT_TIMESTAMP(0) AS TIMESTAMP) = LOCALTIMESTAMP(0);
>> TRUE
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论