diff --git a/src/Functions/FunctionsConversion.h b/src/Functions/FunctionsConversion.h index f9f614e47f2..968893578f8 100644 --- a/src/Functions/FunctionsConversion.h +++ b/src/Functions/FunctionsConversion.h @@ -91,6 +91,9 @@ inline UInt32 extractToDecimalScale(const ColumnWithTypeAndName & named_column) return field.get(); } +/// Function toUnixTimestamp has exactly the same implementation as toDateTime of String type. +struct NameToUnixTimestamp { static constexpr auto name = "toUnixTimestamp"; }; + /** Conversion of number types to each other, enums to numbers, dates and datetimes to numbers and back: done by straight assignment. * (Date is represented internally as number of days from some day; DateTime - as unix timestamp) @@ -111,6 +114,13 @@ struct ConvertImpl using ColVecFrom = typename FromDataType::ColumnType; using ColVecTo = typename ToDataType::ColumnType; + if (std::is_same_v) + { + if (isDate(named_from.type)) + throw Exception("Illegal column " + named_from.column->getName() + " of first argument of function " + Name::name, + ErrorCodes::ILLEGAL_COLUMN); + } + if constexpr ((IsDataTypeDecimal || IsDataTypeDecimal) && !(std::is_same_v || std::is_same_v)) { @@ -923,9 +933,6 @@ struct ConvertImplGenericFromString }; -/// Function toUnixTimestamp has exactly the same implementation as toDateTime of String type. -struct NameToUnixTimestamp { static constexpr auto name = "toUnixTimestamp"; }; - template <> struct ConvertImpl : ConvertImpl {}; diff --git a/tests/queries/0_stateless/01592_toUnixTimestamp_Date.reference b/tests/queries/0_stateless/01592_toUnixTimestamp_Date.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/0_stateless/01592_toUnixTimestamp_Date.sql b/tests/queries/0_stateless/01592_toUnixTimestamp_Date.sql new file mode 100644 index 00000000000..5dc87e31f75 --- /dev/null +++ b/tests/queries/0_stateless/01592_toUnixTimestamp_Date.sql @@ -0,0 +1 @@ +select toUnixTimestamp(today()); -- { serverError 44; }