时间戳失败的Bigquery提取

时间:2019-07-27 12:24:26

标签: google-bigquery

运行以下查询时:

SELECT EXTRACT(HOUR FROM TIMESTAMP '2018-07-09T02:40:23.652Z' AT TIME ZONE 'US/Eastern')

它返回预期的结果:22

但是在运行时:

SELECT start_ts, EXTRACT(HOUR FROM TIMESTAMP TIMESTAMP_MICROS(CAST(1000000 * start_ts AS INT64)) AT TIME ZONE 'US/Eastern') as calc 
    from SOME_CALCS

引发错误:

  

语法错误:应为“)”或关键字AT,但有标识符   “ TIMESTAMP_MICROS”在[1:46]

我所要做的只是将字符串替换为TIMESTAMP_MICROS。

2 个答案:

答案 0 :(得分:0)

对于BigQuery Standard SQL,您应该使用(假设start_ts的格式为:1563026408.17193)

SELECT start_ts, 
  EXTRACT(HOUR FROM DATETIME(TIMESTAMP_MICROS(CAST(1000000 * start_ts AS INT64)), 'US/Eastern')) as calc
FROM SOME_CALCS

答案 1 :(得分:0)

您只需要在代码中不需要关键字Not Found

timestamp

select extract( hour from timestamp_micros( cast(1563456789.012345 * 1000000 as int64) ) at time zone 'US/Eastern') 已经为您返回了时间戳记对象: timestamp_micros