我正在使用 Java 和 SQL 查询 BigQuery 中的表。我想实现以下目标:
- 拉表
- 将字符串(例如 2018 年 1 月 8 日)重新格式化为时间戳(例如 2018-01-08 23:59:28 UTC)
- 将所有新数据推送回新表或现有表
目前,我成功地拉动了 table :
QueryJobConfiguration queryConfig =
QueryJobConfiguration.newBuilder(
"SELECT *"
+ "FROM `MyTable` "
+ "LIMIT 10")
.setUseLegacySql(false)
.build();
是否可以包含一个 SQL 更新语句,该语句采用现有的字符串时间字段并将其重新格式化以匹配时间戳格式?我知道初始时间字符串不包含足够的信息来作为时间戳。我可以接受缺失值为 0 的值(例如 00:00:00 UTC)
最佳答案
Is it possible to include a SQL update statement that takes the existing String time field and reformats it to match the Timestamp format?
请参阅下面的 BigQuery 标准 SQL 示例
#standardSQL
WITH `project.dataset.table` AS (
SELECT 'Jan 08 2018' AS date_as_string
)
SELECT date_as_string, PARSE_TIMESTAMP('%b %d %Y', date_as_string) date_as_timestamp
FROM `project.dataset.table`
结果
Row date_as_string date_as_timestamp
1 Jan 08 2018 2018-01-08 00:00:00 UTC
关于SQL 重新格式化时间戳字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54350460/