diff --git a/docs/en/sql-reference/data-types/special-data-types/interval.md b/docs/en/sql-reference/data-types/special-data-types/interval.md index c89c2e78752..bedbcf0bd28 100644 --- a/docs/en/sql-reference/data-types/special-data-types/interval.md +++ b/docs/en/sql-reference/data-types/special-data-types/interval.md @@ -8,10 +8,6 @@ sidebar_label: Interval The family of data types representing time and date intervals. The resulting types of the [INTERVAL](../../../sql-reference/operators/index.md#operator-interval) operator. -:::note -`Interval` data type values can’t be stored in tables. -::: - Structure: - Time interval as an unsigned integer value. @@ -19,6 +15,9 @@ Structure: Supported interval types: +- `NANOSECOND` +- `MICROSECOND` +- `MILLISECOND` - `SECOND` - `MINUTE` - `HOUR` diff --git a/src/DataTypes/DataTypeInterval.h b/src/DataTypes/DataTypeInterval.h index 83d89a73460..05abe1d9b24 100644 --- a/src/DataTypes/DataTypeInterval.h +++ b/src/DataTypes/DataTypeInterval.h @@ -11,9 +11,6 @@ namespace DB * * Mostly the same as Int64. * But also tagged with interval kind. - * - * Intended usage is for temporary elements in expressions, - * not for storing values in tables. */ class DataTypeInterval final : public DataTypeNumberBase { @@ -34,7 +31,6 @@ public: bool equals(const IDataType & rhs) const override; bool isParametric() const override { return true; } - bool cannotBeStoredInTables() const override { return true; } bool isCategorial() const override { return false; } bool canBeInsideNullable() const override { return true; } }; diff --git a/tests/queries/0_stateless/02724_persist_interval_type.reference b/tests/queries/0_stateless/02724_persist_interval_type.reference new file mode 100644 index 00000000000..9139216d644 --- /dev/null +++ b/tests/queries/0_stateless/02724_persist_interval_type.reference @@ -0,0 +1,4 @@ +2023-01-01 00:00:01.000000001 2023-01-01 02:00:00.000000001 2023-01-01 00:00:00.000000004 1 2 0 +2023-01-01 00:00:02.000000001 2023-01-01 03:00:00.000000001 2023-01-01 00:00:00.000000005 2 3 0 +2023-01-01 00:00:01.000000001 2023-01-01 02:00:00.000000001 2023-01-01 00:00:00.000000004 1 2 0 +2023-01-01 00:00:02.000000001 2023-01-01 03:00:00.000000001 2023-01-01 00:00:00.000000005 2 3 0 diff --git a/tests/queries/0_stateless/02724_persist_interval_type.sql b/tests/queries/0_stateless/02724_persist_interval_type.sql new file mode 100644 index 00000000000..72133aceb00 --- /dev/null +++ b/tests/queries/0_stateless/02724_persist_interval_type.sql @@ -0,0 +1,9 @@ + +DROP TABLE IF EXISTS saved_intervals_tmp; +DROP TABLE IF EXISTS saved_intervals_mgt; +create table saved_intervals_tmp Engine=Memory as SELECT number as EventID, toIntervalSecond(number+1) as v1, toIntervalHour(number+2) as v2, toIntervalNanosecond(number+3) as v3 from numbers(2); +create table saved_intervals_mgt Engine=MergeTree() ORDER BY EventID as SELECT number as EventID, toIntervalSecond(number+1) as v1, toIntervalHour(number+2) as v2, toIntervalNanosecond(number+3) as v3 from numbers(2); +with toDateTime64('2023-01-01 00:00:00.000000001', 9, 'US/Eastern') as c select c+v1 as c_v1, c+v2 as c_v2, c+v3 as c_v3, date_diff(second, c, c_v1), date_diff(hour, c, c_v2), date_diff(second, c, c_v3) from saved_intervals_tmp; +with toDateTime64('2023-01-01 00:00:00.000000001', 9, 'US/Eastern') as c select c+v1 as c_v1, c+v2 as c_v2, c+v3 as c_v3, date_diff(second, c, c_v1), date_diff(hour, c, c_v2), date_diff(second, c, c_v3) from saved_intervals_mgt; +DROP TABLE IF EXISTS saved_intervals_tmp; +DROP TABLE IF EXISTS saved_intervals_mgt; \ No newline at end of file