【问题标题】:How to cast date Strings to DateTime format with extended parsing in ClickHouse?如何在 ClickHouse 中通过扩展解析将日期字符串转换为 DateTime 格式?
【发布时间】:2020-04-29 22:00:43
【问题描述】:

我有一个带有如下时间戳的字符串字段:“2020-01-13T07:34:25.804445Z”。我想将它解析为日期时间(例如,在 Grafana 过滤器中使用)。但是我收到了这个错误:

SELECT SELECT "@timestamp" AS timestamp, CAST(timestamp AS DateTime) as datetime from table

Cannot parse string '2020-01-13T06:55:05.704Z' as DateTime: syntax error at position 19 (parsed just '2020-01-13T06:55:05').

我发现变量date_time_input_format on documentation“允许扩展解析”。但它表示此设置不适用于日期和时间功能。那么如何将带时区的字符串日期转换为 DateTime?

【问题讨论】:

  • 实际上,这个“date_time_input_format”允许我声明字段和日期时间,并直接将我的“扩展”时间戳添加到其中,而无需强制转换。

标签: casting clickhouse


【解决方案1】:
SELECT parseDateTimeBestEffortOrNull('2020-01-13T07:34:25.804445Z')

┌─parseDateTimeBestEffortOrNull('2020-01-13T07:34:25.804445Z')─┐
│                                          2020-01-13 07:34:25 │
└──────────────────────────────────────────────────────────────┘

https://clickhouse.yandex/docs/en/query_language/functions/type_conversion_functions/#type_conversion_functions-parsedatetimebesteffort

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-14
    • 1970-01-01
    • 1970-01-01
    • 2016-05-17
    相关资源
    最近更新 更多