You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is possible to compare datetimes. When comparing different datetime types, for example `DATE` and `TIME`, both converted to `DATETIME`.
154
-
The following rule is applied on coversion: a `TIME` applied to today's date; `DATE` is interpreted at midnight.
154
+
The following rule is applied on coversion: a `TIME` applied to today's date; `DATE` is interpreted at midnight. See example below::
155
155
156
156
os> SELECT current_time() > current_date() AS `now.time > today`, typeof(current_time()) AS `now.time.type`, typeof(current_date()) AS `now.date.type`;
@@ -236,8 +236,7 @@ Numeric values ranged from -2147483648 to +2147483647 are recognized as integer
236
236
Date and Time Data Types
237
237
========================
238
238
239
-
The date and time data types are the types that represent temporal values and SQL plugin supports types including DATE, TIME, DATETIME, TIMESTAMP and INTERVAL. By default, the OpenSearch DSL uses date type as the only date and time related type, which has contained all information about an absolute time point. To integrate with SQL language, each of the types other than timestamp is holding part of temporal or timezone information, and the usage to explicitly clarify the date and time types is reflected in the datetime functions (see `Functions <functions.rst>`_ for details), where some functions might have restrictions in the input argument type.
240
-
239
+
The datetime types supported by the SQL plugin are ``DATE``, ``TIME``, ``DATETIME``, ``TIMESTAMP``, and ``INTERVAL``, with date and time being used to represent temporal values. By default, the OpenSearch DSL uses ``date`` type as the only date and time related type as it contains all information about an absolute time point. To integrate with SQL language each of the types other than timestamp hold part of the temporal or timezone information. This information can be used to explicitly clarify the date and time types reflected in the datetime functions (see `Functions <functions.rst>`_ for details), where some functions might have restrictions in the input argument type.
241
240
242
241
Date
243
242
----
@@ -299,7 +298,7 @@ Interval data type represents a temporal duration or a period. The syntax is as
299
298
| Interval | INTERVAL expr unit |
300
299
+----------+--------------------+
301
300
302
-
The expr is any expression that can be iterated to a quantity value eventually, see `Expressions <expressions.rst>`_ for details. The unit represents the unit for interpreting the quantity, including MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER and YEAR.The INTERVAL keyword and the unit specifier are not case sensitive. Note that there are two classes of intervals. Year-week intervals can store years, quarters, months and weeks. Day-time intervals can store days, hours, minutes, seconds and microseconds. Year-week intervals are comparable only with another year-week intervals. These two types of intervals can only comparable with the same type of themselves.
301
+
The expr is any expression that can be iterated to a quantity value eventually, see `Expressions <expressions.rst>`_ for details. The unit represents the unit for interpreting the quantity, including ``MICROSECOND``, ``SECOND``, ``MINUTE``, ``HOUR``, ``DAY``, ``WEEK``, ``MONTH``, ``QUARTER`` and ``YEAR``. The ``INTERVAL`` keyword and the unit specifier are not case sensitive. Note that there are two classes of intervals. Year-week intervals can store years, quarters, months and weeks. Day-time intervals can store days, hours, minutes, seconds and microseconds. Year-week intervals are comparable only with another year-week intervals. These two types of intervals can only comparable with the same type of themselves.
303
302
304
303
305
304
Conversion between date and time types
@@ -320,7 +319,7 @@ Conversion from DATE
320
319
Conversion from TIME
321
320
>>>>>>>>>>>>>>>>>>>>
322
321
323
-
- Time value cannot be converted to any other date and time types since it does not contain any date information, so it is not meaningful to give no date info to a date/datetime/timestamp instance.
322
+
- When time value is converted to any other datetime types, the date part of the new value is filled up with today's date, like with the `CURDATE` function. For example, a time value X converted to a timestamp would produce today's date at time X.
324
323
325
324
326
325
Conversion from DATETIME
@@ -354,6 +353,82 @@ A string can also represent and be converted to date and time types (except to i
Please, see `more examples here <../dql/expressions.rst#toc-entry-15>`_.
357
+
358
+
Date formats
359
+
------------
360
+
361
+
SQL plugin supports all named formats for OpenSearch ``date`` data type, custom formats and their combination. Please, refer to `OpenSearch docs <https://opensearch.org/docs/latest/field-types/supported-field-types/date/>`_ for format description.
362
+
Plugin detects which type of data is stored in ``date`` field according to formats given and returns results in the corresponding SQL types.
363
+
Given an index with the following mapping.
364
+
365
+
.. code-block:: json
366
+
367
+
{
368
+
"mappings" : {
369
+
"properties" : {
370
+
"date1" : {
371
+
"type" : "date",
372
+
"format": "yyyy-MM-dd"
373
+
},
374
+
"date2" : {
375
+
"type" : "date",
376
+
"format": "date_time_no_millis"
377
+
},
378
+
"date3" : {
379
+
"type" : "date",
380
+
"format": "hour_minute_second"
381
+
},
382
+
"date4" : {
383
+
"type" : "date"
384
+
},
385
+
"date5" : {
386
+
"type" : "date",
387
+
"format": "yyyy-MM-dd || time"
388
+
}
389
+
}
390
+
}
391
+
}
392
+
393
+
Querying such index will provide a response with ``schema`` block as shown below.
0 commit comments