diff --git a/docs/reference/sql/functions/date-time.asciidoc b/docs/reference/sql/functions/date-time.asciidoc index 0ee0d39f30a..de173f3af06 100644 --- a/docs/reference/sql/functions/date-time.asciidoc +++ b/docs/reference/sql/functions/date-time.asciidoc @@ -153,7 +153,8 @@ CURRENT_TIMESTAMP(precision <1>) Returns the date/time when the current query reached the server. As a function, `CURRENT_TIMESTAMP()` accepts _precision_ as an optional -parameter for rounding the second fractional digits (nanoseconds). +parameter for rounding the second fractional digits (nanoseconds). The default _precision_ is 3, +meaning a milliseconds precision current date/time will be returned. This method always returns the same value for its every occurrence within the same query. diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/CurrentDateTime.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/CurrentDateTime.java index 8224ef090b7..6ca9607d893 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/CurrentDateTime.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/CurrentDateTime.java @@ -34,7 +34,7 @@ public class CurrentDateTime extends CurrentFunction { } static ZonedDateTime nanoPrecision(ZonedDateTime zdt, Expression precisionExpression) { - int precision = precisionExpression != null ? Foldables.intValueOf(precisionExpression) : 0; + int precision = precisionExpression != null ? Foldables.intValueOf(precisionExpression) : 3; int nano = zdt.getNano(); if (precision >= 0 && precision < 10) { // remove the remainder diff --git a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/CurrentDateTimeTests.java b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/CurrentDateTimeTests.java index d9cb681d03f..405d4805410 100644 --- a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/CurrentDateTimeTests.java +++ b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/expression/function/scalar/datetime/CurrentDateTimeTests.java @@ -9,10 +9,12 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.datetime; import org.elasticsearch.xpack.sql.TestUtils; import org.elasticsearch.xpack.sql.expression.Expression; import org.elasticsearch.xpack.sql.expression.Literal; +import org.elasticsearch.xpack.sql.session.Configuration; import org.elasticsearch.xpack.sql.tree.AbstractNodeTestCase; import java.time.ZoneId; import java.time.ZonedDateTime; +import java.time.temporal.ChronoField; import java.util.Objects; import static org.elasticsearch.xpack.sql.tree.Source.EMPTY; @@ -62,4 +64,15 @@ public class CurrentDateTimeTests extends AbstractNodeTestCase