standardSQL:无法从时间戳中提取DAY

时间:2017-06-23 08:37:23

标签: timestamp google-bigquery standard-sql

我无法使用EXTRACT()函数从名为 repository.created_at 的时间戳变量中提取天数。

#standardSQL
SELECT repository.created_at AS fechas,
       EXTRACT(DAY FROM DATE repository.created_at)
FROM `bigquery-public-data.samples.github_nested`
LIMIT 100

如何解决?

2 个答案:

答案 0 :(得分:3)

#standardSQL
SELECT 
  repository.created_at AS fechas,
  EXTRACT(DAY FROM PARSE_TIMESTAMP('%Y/%m/%d %X %z', repository.created_at))
FROM `bigquery-public-data.samples.github_nested`
LIMIT 100

答案 1 :(得分:1)

字段repository.created_at的类型为STRING。在提取日期之前,您需要将其解析为日期。

这应该有效:

SELECT repository.created_at AS fechas,
       EXTRACT(DAY FROM PARSE_DATE("%Y/%m/%d", 
SUBSTR(repository.created_at, 0, 10)))
FROM `bigquery-public-data.samples.github_nested`
LIMIT 100