You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.15 10:33:04