我有一个表,其中有一列名为“ 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中显示时间戳中的时间值?
谢谢
答案 0 :(得分:1)
您可以使用EXTRACT函数提取时间并像这样传递时区
select EXTRACT(TIME FROM CURRENT_TIMESTAMP() AT TIME ZONE 'UTC') as Time;
答案 1 :(得分:1)
以下是用于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`