如何在 BigQuery 的 table 中显示时间戳类型列的时间?
How to show time from a column of timestamp type in table at BigQuery?
我有一个 table,其中有一列名为 "INTERACTION_TIMESTAMP"。
我想显示该特定列的日期和时间格式。
到目前为止,我已经尝试了以下代码:
SELECT
USERID as UserId,
INTERACTION_TIMESTAMP,
EXTRACT(ISOWEEK FROM INTERACTION_TIMESTAMP) as IsoWeek,
EXTRACT(DATE from INTERACTION_TIMESTAMP) as date,
EXTRACT(DAYOFWEEK FROM INTERACTION_TIMESTAMP)-1 as DayOfWeek,
PARSE_TIMESTAMP("%H", INTERACTION_TIMESTAMP, "UTC") as Time;
CONCAT(CAST(JOURNEY_ID AS STRING),"-", CAST(JOURNEY_ACTIONID AS STRING)) as JobId,
CASE
WHEN INTERACTION_TYPE = 0 THEN "open"
WHEN INTERACTION_TYPE = 1 THEN "click"
ELSE null
END AS Open_Click
FROM
`XXXXXXXXX.database_name`
但是,BigQuery 总是从该行代码中发出错误消息:
PARSE_TIMESTAMP("%H", INTERACTION_TIMESTAMP, "UTC") as Time;
错误消息说(据我所知)PARSE_TIMESTAMP
与本网站显示的语法不匹配:PARSE_TIMESTAMP documentation
如何处理来自 INTERACTION_TIMESTAMP
的字符串,以便我可以在 BigQuery 中显示时间戳的时间值?
谢谢
您可以使用 EXTRACT 函数提取时间并像这样传递时区
select EXTRACT(TIME FROM CURRENT_TIMESTAMP() AT TIME ZONE 'UTC') as Time;
以下适用于 BigQuery 标准 SQL
而不是 PARSE_TIMESTAMP
你应该使用 FORMAT_TIMESTAMP
SELECT
USERID as UserId,
INTERACTION_TIMESTAMP,
EXTRACT(ISOWEEK FROM INTERACTION_TIMESTAMP) as IsoWeek,
EXTRACT(DATE from INTERACTION_TIMESTAMP) as date,
EXTRACT(DAYOFWEEK FROM INTERACTION_TIMESTAMP)-1 as DayOfWeek,
FORMAT_TIMESTAMP("%H", INTERACTION_TIMESTAMP, "UTC") as Time,
CONCAT(CAST(JOURNEY_ID AS STRING),"-", CAST(JOURNEY_ACTIONID AS STRING)) as JobId,
CASE
WHEN INTERACTION_TYPE = 0 THEN "open"
WHEN INTERACTION_TYPE = 1 THEN "click"
ELSE null
END AS Open_Click
FROM
`XXXXXXXXX.database_name`
我有一个 table,其中有一列名为 "INTERACTION_TIMESTAMP"。
我想显示该特定列的日期和时间格式。
到目前为止,我已经尝试了以下代码:
SELECT
USERID as UserId,
INTERACTION_TIMESTAMP,
EXTRACT(ISOWEEK FROM INTERACTION_TIMESTAMP) as IsoWeek,
EXTRACT(DATE from INTERACTION_TIMESTAMP) as date,
EXTRACT(DAYOFWEEK FROM INTERACTION_TIMESTAMP)-1 as DayOfWeek,
PARSE_TIMESTAMP("%H", INTERACTION_TIMESTAMP, "UTC") as Time;
CONCAT(CAST(JOURNEY_ID AS STRING),"-", CAST(JOURNEY_ACTIONID AS STRING)) as JobId,
CASE
WHEN INTERACTION_TYPE = 0 THEN "open"
WHEN INTERACTION_TYPE = 1 THEN "click"
ELSE null
END AS Open_Click
FROM
`XXXXXXXXX.database_name`
但是,BigQuery 总是从该行代码中发出错误消息:
PARSE_TIMESTAMP("%H", INTERACTION_TIMESTAMP, "UTC") as Time;
错误消息说(据我所知)PARSE_TIMESTAMP
与本网站显示的语法不匹配:PARSE_TIMESTAMP documentation
如何处理来自 INTERACTION_TIMESTAMP
的字符串,以便我可以在 BigQuery 中显示时间戳的时间值?
谢谢
您可以使用 EXTRACT 函数提取时间并像这样传递时区
select EXTRACT(TIME FROM CURRENT_TIMESTAMP() AT TIME ZONE 'UTC') as Time;
以下适用于 BigQuery 标准 SQL
而不是 PARSE_TIMESTAMP
你应该使用 FORMAT_TIMESTAMP
SELECT
USERID as UserId,
INTERACTION_TIMESTAMP,
EXTRACT(ISOWEEK FROM INTERACTION_TIMESTAMP) as IsoWeek,
EXTRACT(DATE from INTERACTION_TIMESTAMP) as date,
EXTRACT(DAYOFWEEK FROM INTERACTION_TIMESTAMP)-1 as DayOfWeek,
FORMAT_TIMESTAMP("%H", INTERACTION_TIMESTAMP, "UTC") as Time,
CONCAT(CAST(JOURNEY_ID AS STRING),"-", CAST(JOURNEY_ACTIONID AS STRING)) as JobId,
CASE
WHEN INTERACTION_TYPE = 0 THEN "open"
WHEN INTERACTION_TYPE = 1 THEN "click"
ELSE null
END AS Open_Click
FROM
`XXXXXXXXX.database_name`