Npgsql批量插入PostgreSQL整数数组字段时的类型错误解决求助
Npgsql批量插入PostgreSQL整数数组字段时的类型错误解决求助
各位好,我现在碰到一个Npgsql操作PostgreSQL的问题,想请大家帮忙看看怎么解决:
我的PostgreSQL表inventory里有一个integer[]类型的slots字段,我想用unnest来批量填充这个字段,写了下面的测试代码:
cmd.CommandText = "INSERT INTO inventory (slots) " + "SELECT t.slots " + "FROM UNNEST(@slots) AS t(slots) " + "RETURNING inventory_id"; cmd.Parameters.AddWithValue("@slots", new int[10][]);
这段代码原本是想插入10条带有空整数数组的记录,但运行时我遇到了如下错误:
Error: The CRL array type System.Int32[][] isn't supported by Npgsql
or your PostgreSQL. If you wish to map it to an PostgreSQL composite
type array you need to register it before usage.
我尝试过在参数配置里指定NpgsqlDbType.Array | NpgsqlDbType.Integer,但还是没能解决问题。
有没有简单的解决方案呢?
备注:内容来源于stack exchange,提问作者Michal Krča
相关产品推荐
相关产品推荐

