mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-14 10:22:10 +00:00
Merge pull request #70597 from bigo-sg/toUnixTimestamp-fix
Add function toUnixTimestamp64Second
This commit is contained in:
commit
b51df5655c
@ -7228,6 +7228,45 @@ Result:
|
|||||||
└──────────────────────────────┘
|
└──────────────────────────────┘
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## toUnixTimestamp64Second
|
||||||
|
|
||||||
|
Converts a `DateTime64` to a `Int64` value with fixed second precision. The input value is scaled up or down appropriately depending on its precision.
|
||||||
|
|
||||||
|
:::note
|
||||||
|
The output value is a timestamp in UTC, not in the timezone of `DateTime64`.
|
||||||
|
:::
|
||||||
|
|
||||||
|
**Syntax**
|
||||||
|
|
||||||
|
```sql
|
||||||
|
toUnixTimestamp64Second(value)
|
||||||
|
```
|
||||||
|
|
||||||
|
**Arguments**
|
||||||
|
|
||||||
|
- `value` — DateTime64 value with any precision. [DateTime64](../data-types/datetime64.md).
|
||||||
|
|
||||||
|
**Returned value**
|
||||||
|
|
||||||
|
- `value` converted to the `Int64` data type. [Int64](../data-types/int-uint.md).
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
|
||||||
|
Query:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
WITH toDateTime64('2009-02-13 23:31:31.011', 3, 'UTC') AS dt64
|
||||||
|
SELECT toUnixTimestamp64Second(dt64);
|
||||||
|
```
|
||||||
|
|
||||||
|
Result:
|
||||||
|
|
||||||
|
```response
|
||||||
|
┌─toUnixTimestamp64Second(dt64)─┐
|
||||||
|
│ 1234567891 │
|
||||||
|
└───────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
## toUnixTimestamp64Micro
|
## toUnixTimestamp64Micro
|
||||||
|
|
||||||
Converts a `DateTime64` to a `Int64` value with fixed microsecond precision. The input value is scaled up or down appropriately depending on its precision.
|
Converts a `DateTime64` to a `Int64` value with fixed microsecond precision. The input value is scaled up or down appropriately depending on its precision.
|
||||||
|
13
src/Functions/toUnixTimestamp64.cpp
Normal file
13
src/Functions/toUnixTimestamp64.cpp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#include <Functions/FunctionUnixTimestamp64.h>
|
||||||
|
#include <Functions/FunctionFactory.h>
|
||||||
|
|
||||||
|
namespace DB
|
||||||
|
{
|
||||||
|
|
||||||
|
REGISTER_FUNCTION(ToUnixTimestamp64Second)
|
||||||
|
{
|
||||||
|
factory.registerFunction("toUnixTimestamp64Second",
|
||||||
|
[](ContextPtr){ return std::make_shared<FunctionToUnixTimestamp64>(0, "toUnixTimestamp64Second"); });
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,8 +1,8 @@
|
|||||||
const column
|
const column
|
||||||
2019-09-16 19:20:12.345 1568650812345 1568650812345000 1568650812345000000
|
2019-09-16 19:20:12.345 1568650812345 1568650812345000 1568650812345000000 1568650812
|
||||||
2019-09-16 19:20:12.345678 1568650812345 1568650812345678 1568650812345678000
|
2019-09-16 19:20:12.345678 1568650812345 1568650812345678 1568650812345678000 1568650812
|
||||||
2019-09-16 19:20:12.345678910 1568650812345 1568650812345678 1568650812345678910
|
2019-09-16 19:20:12.345678910 1568650812345 1568650812345678 1568650812345678910 1568650812
|
||||||
non-const column
|
non-const column
|
||||||
2019-09-16 19:20:12.345 1568650812345 1568650812345000 1568650812345000000
|
2019-09-16 19:20:12.345 1568650812345 1568650812345000 1568650812345000000 1568650812
|
||||||
2019-09-16 19:20:12.345678 1568650812345 1568650812345678 1568650812345678000
|
2019-09-16 19:20:12.345678 1568650812345 1568650812345678 1568650812345678000 1568650812
|
||||||
2019-09-16 19:20:12.345678910 1568650812345 1568650812345678 1568650812345678910
|
2019-09-16 19:20:12.345678910 1568650812345 1568650812345678 1568650812345678910 1568650812
|
||||||
|
@ -2,32 +2,35 @@
|
|||||||
SELECT toUnixTimestamp64Milli(); -- {serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH}
|
SELECT toUnixTimestamp64Milli(); -- {serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH}
|
||||||
SELECT toUnixTimestamp64Micro(); -- {serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH}
|
SELECT toUnixTimestamp64Micro(); -- {serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH}
|
||||||
SELECT toUnixTimestamp64Nano(); -- {serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH}
|
SELECT toUnixTimestamp64Nano(); -- {serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH}
|
||||||
|
SELECT toUnixTimestamp64Second(); -- {serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH}
|
||||||
|
|
||||||
SELECT toUnixTimestamp64Milli('abc'); -- {serverError ILLEGAL_TYPE_OF_ARGUMENT}
|
SELECT toUnixTimestamp64Milli('abc'); -- {serverError ILLEGAL_TYPE_OF_ARGUMENT}
|
||||||
SELECT toUnixTimestamp64Micro('abc'); -- {serverError ILLEGAL_TYPE_OF_ARGUMENT}
|
SELECT toUnixTimestamp64Micro('abc'); -- {serverError ILLEGAL_TYPE_OF_ARGUMENT}
|
||||||
SELECT toUnixTimestamp64Nano('abc'); -- {serverError ILLEGAL_TYPE_OF_ARGUMENT}
|
SELECT toUnixTimestamp64Nano('abc'); -- {serverError ILLEGAL_TYPE_OF_ARGUMENT}
|
||||||
|
SELECT toUnixTimestamp64Second('abc'); -- {serverError ILLEGAL_TYPE_OF_ARGUMENT}
|
||||||
|
|
||||||
SELECT toUnixTimestamp64Milli('abc', 123); -- {serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH}
|
SELECT toUnixTimestamp64Milli('abc', 123); -- {serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH}
|
||||||
SELECT toUnixTimestamp64Micro('abc', 123); -- {serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH}
|
SELECT toUnixTimestamp64Micro('abc', 123); -- {serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH}
|
||||||
SELECT toUnixTimestamp64Nano('abc', 123); -- {serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH}
|
SELECT toUnixTimestamp64Nano('abc', 123); -- {serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH}
|
||||||
|
SELECT toUnixTimestamp64Second('abc', 123); -- {serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH}
|
||||||
|
|
||||||
SELECT 'const column';
|
SELECT 'const column';
|
||||||
WITH toDateTime64('2019-09-16 19:20:12.345678910', 3, 'Asia/Istanbul') AS dt64
|
WITH toDateTime64('2019-09-16 19:20:12.345678910', 3, 'Asia/Istanbul') AS dt64
|
||||||
SELECT dt64, toUnixTimestamp64Milli(dt64), toUnixTimestamp64Micro(dt64), toUnixTimestamp64Nano(dt64);
|
SELECT dt64, toUnixTimestamp64Milli(dt64), toUnixTimestamp64Micro(dt64), toUnixTimestamp64Nano(dt64), toUnixTimestamp64Second(dt64);
|
||||||
|
|
||||||
WITH toDateTime64('2019-09-16 19:20:12.345678910', 6, 'Asia/Istanbul') AS dt64
|
WITH toDateTime64('2019-09-16 19:20:12.345678910', 6, 'Asia/Istanbul') AS dt64
|
||||||
SELECT dt64, toUnixTimestamp64Milli(dt64), toUnixTimestamp64Micro(dt64), toUnixTimestamp64Nano(dt64);
|
SELECT dt64, toUnixTimestamp64Milli(dt64), toUnixTimestamp64Micro(dt64), toUnixTimestamp64Nano(dt64), toUnixTimestamp64Second(dt64);
|
||||||
|
|
||||||
WITH toDateTime64('2019-09-16 19:20:12.345678910', 9, 'Asia/Istanbul') AS dt64
|
WITH toDateTime64('2019-09-16 19:20:12.345678910', 9, 'Asia/Istanbul') AS dt64
|
||||||
SELECT dt64, toUnixTimestamp64Milli(dt64), toUnixTimestamp64Micro(dt64), toUnixTimestamp64Nano(dt64);
|
SELECT dt64, toUnixTimestamp64Milli(dt64), toUnixTimestamp64Micro(dt64), toUnixTimestamp64Nano(dt64), toUnixTimestamp64Second(dt64);
|
||||||
|
|
||||||
SELECT 'non-const column';
|
SELECT 'non-const column';
|
||||||
WITH toDateTime64('2019-09-16 19:20:12.345678910', 3, 'Asia/Istanbul') AS x
|
WITH toDateTime64('2019-09-16 19:20:12.345678910', 3, 'Asia/Istanbul') AS x
|
||||||
SELECT materialize(x) as dt64, toUnixTimestamp64Milli(dt64), toUnixTimestamp64Micro(dt64), toUnixTimestamp64Nano(dt64);
|
SELECT materialize(x) as dt64, toUnixTimestamp64Milli(dt64), toUnixTimestamp64Micro(dt64), toUnixTimestamp64Nano(dt64), toUnixTimestamp64Second(dt64);
|
||||||
|
|
||||||
WITH toDateTime64('2019-09-16 19:20:12.345678910', 6, 'Asia/Istanbul') AS x
|
WITH toDateTime64('2019-09-16 19:20:12.345678910', 6, 'Asia/Istanbul') AS x
|
||||||
SELECT materialize(x) as dt64, toUnixTimestamp64Milli(dt64), toUnixTimestamp64Micro(dt64), toUnixTimestamp64Nano(dt64);
|
SELECT materialize(x) as dt64, toUnixTimestamp64Milli(dt64), toUnixTimestamp64Micro(dt64), toUnixTimestamp64Nano(dt64), toUnixTimestamp64Second(dt64);
|
||||||
|
|
||||||
WITH toDateTime64('2019-09-16 19:20:12.345678910', 9, 'Asia/Istanbul') AS x
|
WITH toDateTime64('2019-09-16 19:20:12.345678910', 9, 'Asia/Istanbul') AS x
|
||||||
SELECT materialize(x) as dt64, toUnixTimestamp64Milli(dt64), toUnixTimestamp64Micro(dt64), toUnixTimestamp64Nano(dt64);
|
SELECT materialize(x) as dt64, toUnixTimestamp64Milli(dt64), toUnixTimestamp64Micro(dt64), toUnixTimestamp64Nano(dt64), toUnixTimestamp64Second(dt64);
|
||||||
|
|
||||||
|
@ -857,6 +857,7 @@ toUnixTimestamp
|
|||||||
toUnixTimestamp64Micro
|
toUnixTimestamp64Micro
|
||||||
toUnixTimestamp64Milli
|
toUnixTimestamp64Milli
|
||||||
toUnixTimestamp64Nano
|
toUnixTimestamp64Nano
|
||||||
|
toUnixTimestamp64Second
|
||||||
toValidUTF8
|
toValidUTF8
|
||||||
toWeek
|
toWeek
|
||||||
toYYYYMM
|
toYYYYMM
|
||||||
|
Loading…
Reference in New Issue
Block a user