Postgres integer arrays as parameters?

前端 未结 3 934
灰色年华
灰色年华 2020-12-13 02:13

I understand that in Postgres pure, you can pass an integer array into a function but that this isn\'t supported in the .NET data provider Npgsql.

I currently have

3条回答
  •  生来不讨喜
    2020-12-13 02:33

    I realize this is an old question, but it took me several hours to find a good solution and thought I'd pass on what I learned here and save someone else the trouble. Try, for example,

    SELECT * FROM some_table WHERE id_column = ANY(@id_list)
    

    where @id_list is bound to an int[] parameter by way of

    command.Parameters.Add("@id_list", NpgsqlDbType.Array | NpgsqlDbType.Integer).Value = my_id_list;
    

    where command is a NpgsqlCommand (using C# and Npgsql in Visual Studio).

提交回复
热议问题