如何使用以编程方式包含多列的 where-in 子句进行 PostgreSQL 查询?

How to do a PostgreSQL query with where-in clause which contains multiple columns programmatically?

我的查询是这样的:

select * from plat_customs_complex
where (code_t,code_s) 
in (('01013090','10'),('01029010','90'));

它在 psql 控制台中运行良好。我的问题是如何在客户端代码中执行此查询。(通过 C# 或 Java)

而且我已经知道以下代码运行良好(C#):

string[] codeT = new string[]{"01013090","01029010"};    
connection.Query("SELECT * FROM plat_customs_complex WHERE code_t=ANY(@CodeT)",
new { CodeT = codeT });

最后,我发现 unnest 函数可以提供帮助。

纯粹的SQL就是这样:

select * from plat_customs_complex
where (code_t,code_s) = ANY(select * from unnest(ARRAY['01013090','01029010'],ARRAY['10','90']))

可以轻松将其转换为 C# 代码:

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});