Skip to content

Commit 9ac223c

Browse files
authored
SQL: Add alias DATETRUNC to DATE_TRUNC function (#47173)
To be on the safe side in terms of use cases also add the alias DATETRUNC to the DATE_TRUNC function. Follows: #46473
1 parent ff99bc1 commit 9ac223c

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

docs/reference/sql/functions/date-time.asciidoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ Currently, using a _precision_ greater than 3 doesn't make any difference to the
249249
function as the maximum number of second fractional digits returned is 3 (milliseconds).
250250

251251
[[sql-functions-datetime-trunc]]
252-
==== `DATE_TRUNC`
252+
==== `DATE_TRUNC/DATETRUNC`
253253

254254
.Synopsis:
255255
[source, sql]
@@ -269,7 +269,7 @@ DATE_TRUNC(
269269
.Description:
270270

271271
Truncate the date/datetime to the specified unit by setting all fields that are less significant than the specified
272-
one to zero (or one, for day, day of week and month).
272+
one to zero (or one, for day, day of week and month). If any of the two arguments is `null` a `null` is returned.
273273

274274
[cols="^,^"]
275275
|===

x-pack/plugin/sql/qa/src/main/resources/command.csv-spec

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ CURRENT_DATE |SCALAR
3939
CURRENT_TIME |SCALAR
4040
CURRENT_TIMESTAMP|SCALAR
4141
CURTIME |SCALAR
42+
DATETRUNC |SCALAR
4243
DATE_TRUNC |SCALAR
4344
DAY |SCALAR
4445
DAYNAME |SCALAR

x-pack/plugin/sql/qa/src/main/resources/docs/docs.csv-spec

+3-2
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ CURRENT_DATE |SCALAR
235235
CURRENT_TIME |SCALAR
236236
CURRENT_TIMESTAMP|SCALAR
237237
CURTIME |SCALAR
238+
DATETRUNC |SCALAR
238239
DATE_TRUNC |SCALAR
239240
DAY |SCALAR
240241
DAYNAME |SCALAR
@@ -2425,7 +2426,7 @@ SELECT DATE_TRUNC('millennium', '2019-09-04T11:22:33.123Z'::datetime) AS millenn
24252426

24262427
truncateDateTimeWeek
24272428
// tag::truncateDateTimeWeek
2428-
SELECT DATE_TRUNC('week', '2019-08-24T11:22:33.123Z'::datetime) AS week;
2429+
SELECT DATETRUNC('week', '2019-08-24T11:22:33.123Z'::datetime) AS week;
24292430

24302431
week
24312432
------------------------
@@ -2457,7 +2458,7 @@ SELECT DATE_TRUNC('decade', CAST('2019-09-04' AS DATE)) AS decades;
24572458
truncateDateQuarter
24582459
schema::quarter:ts
24592460
// tag::truncateDateQuarter
2460-
SELECT DATE_TRUNC('quarters', CAST('2019-09-04' AS DATE)) AS quarter;
2461+
SELECT DATETRUNC('quarters', CAST('2019-09-04' AS DATE)) AS quarter;
24612462

24622463
quarter
24632464
------------------------

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/FunctionRegistry.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ private void defineDefaultFunctions() {
194194
def(DayOfMonth.class, DayOfMonth::new, "DAY_OF_MONTH", "DAYOFMONTH", "DAY", "DOM"),
195195
def(DayOfWeek.class, DayOfWeek::new, "DAY_OF_WEEK", "DAYOFWEEK", "DOW"),
196196
def(DayOfYear.class, DayOfYear::new, "DAY_OF_YEAR", "DAYOFYEAR", "DOY"),
197-
def(DateTrunc.class, DateTrunc::new, "DATE_TRUNC"),
197+
def(DateTrunc.class, DateTrunc::new, "DATETRUNC", "DATE_TRUNC"),
198198
def(HourOfDay.class, HourOfDay::new, "HOUR_OF_DAY", "HOUR"),
199199
def(IsoDayOfWeek.class, IsoDayOfWeek::new, "ISO_DAY_OF_WEEK", "ISODAYOFWEEK", "ISODOW", "IDOW"),
200200
def(IsoWeekOfYear.class, IsoWeekOfYear::new, "ISO_WEEK_OF_YEAR", "ISOWEEKOFYEAR", "ISOWEEK", "IWOY", "IW"),

0 commit comments

Comments
 (0)