问题
My query is like this:
select * from plat_customs_complex
where (code_t,code_s)
in (('01013090','10'),('01029010','90'));
It runs well in psql console. My question is how to perform this query in client code.(via C# or Java)
And I already know the following code works well(C#):
string[] codeT = new string[]{"01013090","01029010"};
connection.Query("SELECT * FROM plat_customs_complex WHERE code_t=ANY(@CodeT)",
new { CodeT = codeT });
回答1:
Finally, I found the unnest
function can help.
Pure SQL is like that:
select * from plat_customs_complex
where (code_t,code_s) = ANY(select * from unnest(ARRAY['01013090','01029010'],ARRAY['10','90']))
Can convert it to C# code easily:
string[] codeTs = new string[]{"01013090","01029010"};
string[] codeSs = new string[]{"10", "90"};
connection.Query("select * from plat_customs_complex
where (code_t,code_s) = ANY(select * from unnest(@CodeTs, @CodeSs))",
new {CodeTs=codeTs, CodeSs=codeSs});
来源:https://stackoverflow.com/questions/42943106/how-to-do-a-postgresql-query-with-where-in-clause-which-contains-multiple-column