首页 > 解决方案 > 如何从 Big Query 中的元表转换“creation_time”和“last_modified_time”格式列?

问题描述

我运行了查询:

选择 * 从project.dataset.__TABLES__

从特定数据集中获取我所有表的摘要。

我的问题是关于“creation_time”和“last_modified_time”列的格式。它以 13 位数字序列的格式显示日期。

有没有办法将其转换为通用日期格式?

(我期望像 YYYY-mm-dd 这样的格式)

谢谢

标签: google-bigquery

解决方案


该字段包含自纪元以来的毫秒数。您可以使用

TIMESTAMP_MILLIS(creation_time) AS creation_time,
TIMESTAMP_MILLIS(last_modified_time) AS last_modified_time

获得正确的时间戳。

我正在使用类似的东西

SELECT
  * REPLACE(
    TIMESTAMP_MILLIS(creation_time) AS creation_time,
    TIMESTAMP_MILLIS(last_modified_time) AS last_modified_time
  ),
  size_bytes/pow(1024,3) size_gigaBytes
FROM `project.dataset.__TABLES__`

推荐阅读