Help wanted!
The following content of this documentation page has been machine-translated. But unlike other websites, it is not done on the fly. This translated text lives on GitHub repository alongside main ClickHouse codebase and waits for fellow native speakers to make it more human-readable. You can also use the original English version as a reference.
Datetime64
定義された秒以下の精度で、カレンダーの日付と時刻として表すことができるインスタントを時間内に格納することができます
目盛りのサイズ(精密):10-精密 秒
構文:
DateTime64(precision, [timezone])
内部的には、データを ‘ticks’ エポック開始(1970-01-01 00:00:00UTC)以来、Int64として。 目盛りの解像度は、精度パラメータによって決定されます。 さらに、 DateTime64
型は、列全体で同じタイムゾーンを格納することができます。 DateTime64
型の値はテキスト形式で表示され、文字列として指定された値がどのように解析されるか (‘2020-01-01 05:00:01.000’). タイムゾーンは、テーブルの行(またはresultset)には格納されませんが、列メタデータに格納されます。 詳細はを参照。 DateTime.
例
1. テーブルの作成 DateTime64
-列を入力し、そこにデータを挿入する:
CREATE TABLE dt
(
`timestamp` DateTime64(3, 'Europe/Moscow'),
`event_id` UInt8
)
ENGINE = TinyLog
INSERT INTO dt Values (1546300800000, 1), ('2019-01-01 00:00:00', 2)
SELECT * FROM dt
┌───────────────timestamp─┬─event_id─┐
│ 2019-01-01 03:00:00.000 │ 1 │
│ 2019-01-01 00:00:00.000 │ 2 │
└─────────────────────────┴──────────┘
- Datetimeを整数として挿入する場合、適切にスケーリングされたUnixタイムスタンプ(UTC)として扱われます。
1546300800000
(精度3で)を表します'2019-01-01 00:00:00'
UTC しかし、timestamp
列はEurope/Moscow
(UTC+3)タイムゾーンが指定されている場合、文字列として出力すると、値は次のように表示されます'2019-01-01 03:00:00'
- 文字列値をdatetimeとして挿入すると、列タイムゾーンにあるものとして扱われます。
'2019-01-01 00:00:00'
であるとして扱われますEurope/Moscow
タイムゾーンとして保存1546290000000
.
2. フィルタリング DateTime64
値
SELECT * FROM dt WHERE timestamp = toDateTime64('2019-01-01 00:00:00', 3, 'Europe/Moscow')
┌───────────────timestamp─┬─event_id─┐
│ 2019-01-01 00:00:00.000 │ 2 │
└─────────────────────────┴──────────┘
異なり DateTime
, DateTime64
値は変換されません String
自動的に
3. Aのタイムゾーンの取得 DateTime64
-タイプ値:
SELECT toDateTime64(now(), 3, 'Europe/Moscow') AS column, toTypeName(column) AS x
┌──────────────────column─┬─x──────────────────────────────┐
│ 2019-10-16 04:12:04.000 │ DateTime64(3, 'Europe/Moscow') │
└─────────────────────────┴────────────────────────────────┘
4. タイムゾーン変換
SELECT
toDateTime64(timestamp, 3, 'Europe/London') as lon_time,
toDateTime64(timestamp, 3, 'Europe/Moscow') as mos_time
FROM dt
┌───────────────lon_time──┬────────────────mos_time─┐
│ 2019-01-01 00:00:00.000 │ 2019-01-01 03:00:00.000 │
│ 2018-12-31 21:00:00.000 │ 2019-01-01 00:00:00.000 │
└─────────────────────────┴─────────────────────────┘