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
- 'Type mismatch: can not convert string(''2022-01-01'') to datetime'
631
+
...
632
+
633
+
tarantool> insert into t2 values (cast('2022-01-01' as datetime));
634
+
---
635
+
- row_count: 1
636
+
...
637
+
638
+
tarantool> select * from t2;
639
+
---
640
+
- metadata:
641
+
- name: D
642
+
type: datetime
643
+
rows:
644
+
- ['2022-01-01T00:00:00Z']
645
+
...
646
+
647
+
There is no implicit cast available from a string expression to a datetime expression (dislike convention used by majority of SQL vendors).
648
+
In such cases, you need to use explicit cast from a string value to a datetime value (see the example above).
649
+
650
+
You can subtract datetime and datetime, datetime and interval, or add datetime and interval in any order (see examples of such arithmetics in the description of the :ref:`INTERVAL type <sql_data_type_interval>`).
651
+
652
+
The built-in functions related to the DATETIME type are :ref:`DATE_PART() <sql_function_datepart>` and :ref:`NOW() <sql_function_now>`
653
+
654
+
.. _sql_data_type_interval:
655
+
656
+
INTERVAL. Introduced in :tarantool-release:`2.10.0`.
657
+
Similarly to the :ref:`DATETIME <sql_data_type_datetime>` type, you can define a column of the INTERVAL type.
658
+
659
+
.. code-block:: tarantoolsession
660
+
661
+
tarantool> create table T(d datetime primary key, i interval);
662
+
---
663
+
- row_count: 1
664
+
...
665
+
666
+
tarantool> insert into T values (cast('2022-02-02T01:01' as datetime), cast({'year': 1, 'month': 1} as interval));
667
+
---
668
+
- row_count: 1
669
+
...
670
+
671
+
tarantool> select * from t;
672
+
---
673
+
- metadata:
674
+
- name: D
675
+
type: datetime
676
+
- name: I
677
+
type: interval
678
+
rows:
679
+
- ['2022-02-02T01:01:00Z', '+1 years, 1 months']
680
+
...
681
+
682
+
Dislike DATETIME, INTERVAL cannot be a part of an index.
683
+
684
+
There is no implicit cast available for conversions to an interval from a string or any other type.
685
+
But there is explicit cast allowed from maps (see examples below).
686
+
687
+
Intervals can be used in arithmetic operations like ``+`` or ``-`` only with the datetime expression or another interval:
688
+
689
+
.. code-block:: tarantoolsession
690
+
691
+
tarantool> select * from t
692
+
---
693
+
- metadata:
694
+
- name: D
695
+
type: datetime
696
+
- name: I
697
+
type: interval
698
+
rows:
699
+
- ['2022-02-02T01:01:00Z', '+1 years, 1 months']
700
+
...
701
+
702
+
tarantool> select d, d + i, d + cast({'year': 1, 'month': 2} as interval) from t
0 commit comments