【问题标题】:Passing a string array to Redshift将字符串数组传递给 Redshift
【发布时间】:2020-06-02 16:20:54
【问题描述】:

我在 C# 中有一个 List<string>,我想在查询 Redshift 时使用它。例如:

List<string> fieldStringList = new List<string>(){"field1","field2","field3"};
await using var conn = new NpgsqlConnection("My Connection String");
await conn.OpenAsync();    
await using var cmd = new NpgsqlCommand("SELECT TOP 10 * FROM example WHERE field IN (:field);", conn);
cmd.Parameters.AddWithValue("field", NpgsqlDbType.Array | NpgsqlDbType.Varchar, fieldStringList.ToArray());

这会失败并出现异常

Npgsql.PostgresException (0x80004005): 42883: 运算符不存在:字符变化 = 字符变化 []

看起来我正在尝试将 varchar 与 varchar[] 进行比较?

我应该如何将数组传递给 Redshift 查询?

【问题讨论】:

    标签: c# amazon-redshift npgsql


    【解决方案1】:

    IN 运算符不接受数组。请尝试以下操作:

    SELECT TOP 10 * FROM example WHERE field = ANY (:field);
    

    【讨论】:

    • 同样的问题。我认为这适用于 Postgres,但不适用于 Redshift?
    • 这绝对是可能的——以上确实是针对 PG 的(我对 Redshift 了解不多)。那里可能没有解决方案......
    猜你喜欢
    • 2016-12-08
    • 2022-11-26
    • 2016-10-25
    • 2021-08-17
    • 1970-01-01
    • 1970-01-01
    • 2015-09-09
    相关资源
    最近更新 更多