首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尝试将时代代码字段(字符串类型)转换为时间戳

尝试将时代代码字段(字符串类型)转换为时间戳
EN

Stack Overflow用户
提问于 2018-11-21 15:39:12
回答 1查看 111关注 0票数 2

试图从时代代码转换为时间戳,在遗留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 FROMyellowhead-visionbi-rivery.yellowhead_prod.affise_conversions

我所犯的错误:“无效日期”

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-11-21 16:03:52

下面是BigQuery标准SQL的id

代码语言:javascript
复制
#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`  

可以使用虚拟数据进行测试,如下所示

代码语言:javascript
复制
#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`   

有结果

代码语言:javascript
复制
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  
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53415587

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档