[英]Adding local tibble to Postgres database where a column is an interval
我正在尝试向 Postgres 表添加一个条目,其中一列是一个间隔。 但是,我不确定如何将本地 tibble 的列类型转换为间隔。 正如您想象的那样,类型差异会导致数据库不愉快。 有什么办法可以解决这个问题?
library(dbplyr)
library(dplyr)
con <- my_db_con
df1 <- tibble(my_interval = "P3D")
df2 <- tbl(con, sql("select 'P3D'::interval as my_interval"))
# Will error:
rows_upsert(df2, df1, copy = TRUE)
结果错误:
Matching, by = "my_interval"
Error: Failed to prepare query: ERROR: operator does not exist: text = interval
LINE 9: WHERE ("LHS"."my_interval" = "RHS"."my_interval")
^
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
感谢您的时间。
我(希望)在 dbplyr 的开发版本中修复了这个问题。 通过devtools::install_github("tidyverse/dbplyr")
尝试一下。 如果这不起作用,请告诉我。 您还有两种其他可能性可以避免此问题:
types
参数传递列类型copy_to(my_db_con, df1, types = c(my_interval = "interval"))
mutate()
df2_copied <- copy_to(my_db_con, df1) %>% mutate(my_interval = sql("my_interval::interval"))
rows_upsert(df1, df2_copied)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.