【发布时间】:2018-11-02 05:22:46
【问题描述】:
我有一个带有时间戳(无时区)的数据库,我想在使用 collect() 之前将其转换为 timestamptz(带有时区)。到目前为止,我已经尝试了这些:
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 的情况下使用我的本地时区来提取时间戳。
【问题讨论】: