这是基本的,如果我错过了现有的答案,我会道歉。我试图在数据库中选择行userid
匹配我提供的数组中的任何字符串。以下是我尝试过的方法:
query_string = "SELECT * FROM data WHERE userid = ANY([qFupLOnc1,bUVMBxum0,FlYYzQz31]) LIMIT 5"
query_string = "SELECT * FROM data WHERE userid = ANY(['qFupLOnc1','b2VMBxum0','FlYYzQz31']) LIMIT 5"
query_string = "SELECT * FROM data WHERE userid = ANY(ARRAY['qFupLOnc1','bUVMBxum0','FlYYzQz31']) LIMIT 5"
query_string = "SELECT * FROM data WHERE userid = ANY(ARRAY[qFupLOnc1,bUVMBxum0,FlYYzQz31]) LIMIT 5"
query_string = "SELECT * FROM data WHERE userid ANY(ARRAY[qFupLOnc1,bUVMBxum0,FlYYzQz31]) LIMIT 5"
query_string = "SELECT * FROM data WHERE userid ANY(ARRAY['qFupLOnc1','bUVMBxum0','FlYYzQz31']) LIMIT 5"
query_string = "SELECT * FROM data WHERE userid ANY(['qFupLOnc1','bUVMBxum0','FlYYzQz31']) LIMIT 5"
query_string = "SELECT * FROM data WHERE userid ANY([qFupLIOnc1,bU2VMBxum0,FlYYzQz31]) LIMIT 5"
这些都带来了错误。这样做的正确方法是什么?
我通过R包RPostgreSQL
查询数据库,如下所示:
data = dbGetQuery(con, query_string)
答案 0 :(得分:0)
试,
query_string = "SELECT * FROM data WHERE userid like '%foo%'";
答案 1 :(得分:-1)
您想要IN
:
SELECT * FROM data WHERE userid IN ('...', '...', '...');