gpt4 book ai didi

sql - dapper sql in-clause抛出异常

转载 作者:行者123 更新时间:2023-11-29 12:21:16 25 4
gpt4 key购买 nike

这可能是 SELECT * FROM X WHERE id IN (...) with Dapper ORM 的副本

我正在努力实现:

connection.execute("delete from table where id in @ids", new { ids = new int[]{1,2}});

但它不起作用。我总是得到:错误:42883:运算符不存在:integer = integer[]。

即使我这样做:

connection.Query<a>("select * from a where a_id in @ids", new { ids = new int[] { 12, 13 } })

我遇到了同样的异常。我正在使用 Npgsql 访问 postgresql 数据库。你能告诉我我做错了什么吗?

这是第二条语句在数据库中发生的情况:

这是第二条语句的一些日志:

运算符不存在:integer = integer[] at character 33

没有运算符匹配给定的名称和参数类型。您可能需要添加显式类型转换。

select * from a where a_id in ((array[12,13])::int4[])

这是第一个(与上面相同,但最后一行不同)

从 ((array[12,13])::int4[]) 中的 a_id 中删除

最佳答案

我建议您查看 Postgres 文档 Searching in Arrays .简而言之,您应该使用运算符“ANY”或“ALL”,或者手动检查数组中每个值的列。

此 sql 是带有 IN 子句的查询的等效版本:

delete from table where id = any (@ids)

关于sql - dapper sql in-clause抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22573068/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com