提交 2bfb0743 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add LOCALTIME function from the SQL standard

上级 695c4a99
......@@ -3944,10 +3944,14 @@ CURRENT_DATE()
"
"Functions (Time and Date)","CURRENT_TIME","
{ CURRENT_TIME [ () ] | CURTIME() }
{ CURRENT_TIME [ ( [ int ] ) ] | LOCALTIME [ ( [ int ] ) ] | CURTIME() }
","
Returns the current time.
This method always returns the same value within a transaction.
If fractional seconds precision is specified it should be from 0 to 9, 0 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.
These methods always return the same value within a transaction.
","
CURRENT_TIME()
"
......@@ -3957,7 +3961,7 @@ 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.
If fractional seconds precision is specified it should be from 0 to 9, 6 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.
......@@ -3970,7 +3974,7 @@ CURRENT_TIMESTAMP()
{ LOCALTIMESTAMP [ ( [ int ] ) ] | NOW( [ int ] ) }
","
Returns the current timestamp.
If fractional seconds precision is specified it should be from 0 to 9, 9 is default.
If fractional seconds precision is specified it should be from 0 to 9, 6 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.
......
......@@ -504,8 +504,9 @@ 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, LOCALTIMESTAMP, MINUS, NATURAL, NOT, NULL, OFFSET, ON, ORDER, PRIMARY,
ROWNUM, SELECT, SYSDATE, SYSTIME, SYSTIMESTAMP, TODAY, TOP, TRUE, UNION, UNIQUE, WHERE, WITH
IS, JOIN, LIKE, LIMIT, LOCALTIME, 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,
......
......@@ -3160,6 +3160,8 @@ public class Parser {
r = readFunctionWithoutParameters("CURRENT_DATE");
} else if (equalsToken("CURRENT_TIME", name)) {
r = readFunctionWithoutParameters("CURRENT_TIME");
} else if (equalsToken("LOCALTIME", name)) {
r = readFunctionWithoutParameters("LOCALTIME");
} else if (equalsToken("SYSTIME", name)) {
r = readFunctionWithoutParameters("CURRENT_TIME");
} else if (equalsToken("CURRENT", name)) {
......
......@@ -63,6 +63,7 @@ import org.h2.value.ValueLong;
import org.h2.value.ValueNull;
import org.h2.value.ValueResultSet;
import org.h2.value.ValueString;
import org.h2.value.ValueTime;
import org.h2.value.ValueTimestamp;
import org.h2.value.ValueTimestampTimeZone;
import org.h2.value.ValueUuid;
......@@ -293,7 +294,9 @@ public class Function extends Expression implements FunctionCall {
addFunctionNotDeterministic("GETDATE", CURDATE,
0, Value.DATE);
addFunctionNotDeterministic("CURRENT_TIME", CURRENT_TIME,
0, Value.TIME);
VAR_ARGS, Value.TIME);
addFunctionNotDeterministic("LOCALTIME", CURRENT_TIME,
VAR_ARGS, Value.TIME);
addFunctionNotDeterministic("SYSTIME", CURRENT_TIME,
0, Value.TIME);
addFunctionNotDeterministic("CURTIME", CURTIME,
......@@ -829,7 +832,8 @@ public class Function extends Expression implements FunctionCall {
}
case CURTIME:
case CURRENT_TIME: {
result = session.getTransactionStart().convertTo(Value.TIME);
ValueTime vt = (ValueTime) session.getTransactionStart().convertTo(Value.TIME);
result = vt.convertScale(false, v0 == null ? 0 : v0.getInt());
break;
}
case LOCALTIMESTAMP: {
......@@ -839,7 +843,7 @@ public class Function extends Expression implements FunctionCall {
}
case CURRENT_TIMESTAMP: {
ValueTimestampTimeZone vt = session.getTransactionStart();
result = v0 == null ? vt : vt.convertScale(false, v0.getInt());
result = vt.convertScale(false, v0 == null ? 6 : v0.getInt());
break;
}
case DATABASE:
......@@ -2063,6 +2067,7 @@ public class Function extends Expression implements FunctionCall {
min = 1;
break;
case LOCALTIMESTAMP:
case CURRENT_TIME:
case CURRENT_TIMESTAMP:
case RAND:
max = 1;
......
......@@ -1545,9 +1545,10 @@ 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, LOCALTIMESTAMP,
* 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, LOCALTIME,
* 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
......
......@@ -151,7 +151,7 @@ public class ParserUtil {
return KEYWORD;
}
if (additionalKeywords) {
if ("LOCALTIMESTAMP".equals(s)) {
if ("LOCALTIME".equals(s) || "LOCALTIMESTAMP".equals(s)) {
return KEYWORD;
}
}
......
......@@ -21,3 +21,12 @@ select length(now())>18 c1, length(current_timestamp())>18 c2, length(now(0))>18
> ---- ---- ---- ----
> TRUE TRUE TRUE TRUE
> rows: 1
SELECT CAST(CURRENT_TIME AS TIME(9)) = LOCALTIME;
>> TRUE
SELECT CAST(CURRENT_TIME(0) AS TIME(9)) = LOCALTIME(0);
>> TRUE
SELECT CAST(CURRENT_TIME(9) AS TIME(9)) = LOCALTIME(9);
>> TRUE
......@@ -3,8 +3,11 @@
-- Initial Developer: H2 Group
--
SELECT CAST(CURRENT_TIMESTAMP AS TIMESTAMP) = LOCALTIMESTAMP;
SELECT CAST(CURRENT_TIMESTAMP AS TIMESTAMP(9)) = LOCALTIMESTAMP;
>> TRUE
SELECT CAST(CURRENT_TIMESTAMP(0) AS TIMESTAMP) = LOCALTIMESTAMP(0);
SELECT CAST(CURRENT_TIMESTAMP(0) AS TIMESTAMP(9)) = LOCALTIMESTAMP(0);
>> TRUE
SELECT CAST(CURRENT_TIMESTAMP(9) AS TIMESTAMP(9)) = LOCALTIMESTAMP(9);
>> TRUE
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论