尝试从纪元代码转换为时间戳,在旧版SQL中工作正常,而在标准SQL中,我遇到错误。 字段名称custom_field_6(字符串类型字段)代表纪元时间,我想将其转换为时间戳记(在标准SQL中)
在旧版SQL中,我执行了以下操作:
select
custom_field_6 as custom_field_6,
timestamp(custom_field_6) as custom_field_6_convert
FROM [yellowhead-visionbi-rivery:yellowhead_prod.affise_conversions]
在标准sql中:
select
custom_field_6 as custom_field_6,
cast(custom_field_6 as date) as custom_field_6_converted
FROM
yellowhead-visionbi-rivery.yellowhead_prod.affise_conversions``
The error I get:“无效日期”
答案 0 :(得分:1)
BigQuery标准SQL的ID下方
#standardSQL
SELECT
custom_field_6,
TIMESTAMP_SECONDS(CAST(custom_field_6 AS INT64)) custom_field_6_convert
FROM `yellowhead-visionbi-rivery.yellowhead_prod.affise_conversions`
您可以使用以下虚拟数据进行测试
#standardSQL
WITH `project.dataset.table` AS (
SELECT '1540051185' custom_field_6 UNION ALL
SELECT '1540252572'
)
SELECT
custom_field_6,
TIMESTAMP_SECONDS(CAST(custom_field_6 AS INT64)) custom_field_6_convert
FROM `project.dataset.table`
有结果
Row custom_field_6 custom_field_6_convert
1 1540051185 2018-10-20 15:59:45 UTC
2 1540252572 2018-10-22 23:56:12 UTC