0

我有一个带有时间戳(无时区)的数据库,我想在使用collect(). 到目前为止,我已经尝试过这些:

db_tbl %>% mutate_if(lubridate::is.timepoint, funs(CAST))

但是,我不知道如何添加AS timestamptz到这个函数调用

它给了我:

Error in result_create(conn@ptr, statement) : 
  Failed to prepare query: ERROR:  syntax error at or near ")"
LINE 1: SELECT "user_id", "time_zone", CAST("confirmed_at") AS "conf...

db_tbl %>% mutate_if(lubridate::is.timepoint, funs(sql(paste0(., "::timestamptz"))))

但是,我不知道如何paste0()执行而不是被翻译成CONCAT:它给了我:

Applying predicate on the first 100 rows
<SQL>
SELECT "user_id", "time_zone", CONCAT_WS('', "confirmed_at", '::timestamptz') AS "confirmed_at"
FROM (SELECT "user_id", "time_zone", "confirmed_at"
FROM app.app_users) "paiaayosfl"

最终,我试图在没有 R 假设我的本地时区的情况下提取时间戳。

4

1 回答 1

0

对于我们未来的后代:

  .data %>%
    mutate_if(lubridate::is.timepoint, funs(CAST(. %as% timestamptz))) 
于 2018-11-05T21:25:21.350 回答