Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google bigquery BigQuery中的优雅时区转换_Google Bigquery - Fatal编程技术网

Google bigquery BigQuery中的优雅时区转换

Google bigquery BigQuery中的优雅时区转换,google-bigquery,Google Bigquery,我已将数据加载到BigQuery中,并使用东部时间戳从源数据存储为原始时间戳: placed_eastern ------------------- 2018-07-23 00:00:03 默认情况下,BigQuery假定初始时间戳应存储为UTC: 2018-07-23 00:00:03 UTC 问题:我需要修正这个时区假设。 我目前有一个丑陋的黑客来修复这个错误,以确保时间戳被正确存储。这会将时间戳的日期和时间部分提取为字符串,连接它们,然后重新创建时间戳 select placed

我已将数据加载到BigQuery中,并使用东部时间戳从源数据存储为原始时间戳:

placed_eastern
-------------------
2018-07-23 00:00:03
默认情况下,BigQuery假定初始时间戳应存储为UTC:

2018-07-23 00:00:03 UTC
问题:我需要修正这个时区假设。

我目前有一个丑陋的黑客来修复这个错误,以确保时间戳被正确存储。这会将时间戳的日期和时间部分提取为字符串,连接它们,然后重新创建时间戳

select 
  placed_eastern,
  timestamp(
    concat(
      cast(extract(date from placed_eastern) as string), 
      ' ', 
      cast(extract(time from placed_eastern) as string)
    ),
    'US/Eastern'
  ) as actual_placed_utc

问题:是否有一种优雅的文档化方法来处理此问题?

您可以转换为
DATETIME
将时间戳视为逻辑日期/时间,然后使用
US/Eastern
将时间戳转换回
timestamp

SELECT TIMESTAMP(DATETIME(placed_eastern), 'US/Eastern')) AS actual_placed_utc
FROM dataset.table

您可以转换为
DATETIME
将时间戳视为逻辑日期/时间,然后使用
US/Eastern
将时间戳转换回
timestamp

SELECT TIMESTAMP(DATETIME(placed_eastern), 'US/Eastern')) AS actual_placed_utc
FROM dataset.table