首页 > 解决方案 > BigQuery - 无法解析输入字符串

问题描述

我已从 JSON 字段中提取字符串,格式如下,"2020-07-0217:39:02-04:00"存储在名为time_string.

当我使用以下函数时PARSE_TIMESTAMP("%Y-%m-%d%H:%M:%S%Ez", time_string),我收到所有行的“无法解析输入字符串”错误。

如果我直接粘贴一个日期time_string作为解析函数的输入,我会得到一个输出。

询问:SELECT PARSE_TIMESTAMP("%Y-%m-%d%H:%M:%S%Ez", "2020-07-0217:39:02-04:00")

输出:2020-07-02 21:39:02 UTC

我知道这里有多个类似问题的帖子。通读它们,但无法弄清楚这一点。

标签: google-bigquerytimestamp

解决方案


我看到的唯一解释是 - 你的一些time_strings 的格式与你预期的不同

要找到,请在下面运行

#standardSQL
select time_string
from `project.dataset.table`
where SAFE.PARSE_TIMESTAMP("%Y-%m-%d%H:%M:%S%Ez", time_string) is null   

更新

看起来你的一些值用引号括起来

在此处输入图像描述

所以改用下面

select PARSE_TIMESTAMP("%Y-%m-%d%H:%M:%S%Ez", trim(time_string, '"'))

推荐阅读