2

这是基本的,如果我错过了现有的答案,我深表歉意。我正在尝试在数据库中选择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) 
4

2 回答 2

0

尝试,

 query_string = "SELECT * FROM data WHERE userid like '%foo%'";
于 2016-04-06T18:05:50.543 回答
-1

你想要IN

SELECT * FROM data WHERE userid IN ('...', '...', '...');
于 2016-04-06T17:58:37.867 回答