我正在使用dplyr自动SQL后端从数据库表中查询子表.例如
my_tbl <- tbl(my_db, "my_table")
Run Code Online (Sandbox Code Playgroud)
其中,my_table在数据库中的样子
batch_name value
batch_A_1 1
batch_A_2 2
batch_A_2 3
batch_B_1 8
batch_B_2 9
...
Run Code Online (Sandbox Code Playgroud)
batch_A_#无论数字如何,我只想要数据.
如果我在SQL中写这个,我可以使用
select * where batch_name like 'batch_A_%'
Run Code Online (Sandbox Code Playgroud)
如果我是在R写入这一点,我可以用一些方法来得到这样的:grepl(),%in%或str_detect()
# option 1
subtable <- my_tbl %>% select(batch_name, value) %>%
filter(grepl('batch_A_', batch_name, fixed = T))
# option 2
subtable <- my_tbl %>% select(batch_name, value) %>%
filter(str_detect(batch_name, 'batch_A_'))
Run Code Online (Sandbox Code Playgroud)
所有这些都给出了以下Postgres错误: HINT: No function matches the given name and argument types. You might need to …