c# - 如果参数在 IS 之后,Npgsql 会抛出错误

标签 c# postgresql npgsql

我正在尝试使用 Npgsql 来查询具有 NULL 值的行,并且使用一个简单的查询它可以工作,但是如果我使用准备好的语句它会出错。

例如,这个查询可以工作:

SELECT * FROM table WHERE column IS NULL LIMIT 10;

但是这个不会:

// @null is a parameter with a null value (DBNull.Value)
SELECT * FROM table WHERE column IS @null LIMIT 10;

此查询将返回空结果集,但不会出现预期的错误:

// @null is a parameter with a null value (DBNull.Value)
SELECT * FROM table WHERE column = @null LIMIT 10;

我还尝试将 IS 用于 bool 值,使用 = 时它的行为再次符合预期,但在 IS 上抛出了错误。我做错了什么还是这是一个错误?

堆栈跟踪/错误信息:

Npgsql.PostgresException -- External component has thrown an exception.
at Npgsql.NpgsqlConnector.DoReadSingleMessage(DataRowLoadingMode dataRowLoadingMode, Boolean returnNullForAsyncMessage, Boolean isPrependedMessage)
at Npgsql.NpgsqlConnector.ReadSingleMessage(DataRowLoadingMode dataRowLoadingMode, Boolean returnNullForAsyncMessage)
at Npgsql.NpgsqlCommand.Prepare()

所有测试最初都是使用 3.0.4 版和 3.1.9 版运行的。

最佳答案

如评论中所述,ISIS NOT 不是可以单独使用的术语。它们是一个更大的声明的一部分:IS NULLIS NOT NULL 不能分开。

关于c# - 如果参数在 IS 之后,Npgsql 会抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42166225/

相关文章:

c# - 通过直接传递获取属性名称和类型

c# - 通过 HttpTrigger 将值/参数传递给 Azure Powershell 函数

c# - 在 C# 中有条件地调用重写的基方法

python - 如何在 SQLAlchemy/Postgres 中限制每个 `group_by` 的 N 个结果?

postgresql - 使用集成安全性连接到 PostgreSQL 或回退到公共(public)登录

C# 枚举到 postgres 枚举

c# - C#中的继承

java - jOOQ 和 PostgreSQL : mapping nested json object extracted from complex jsonb into custom type

java - hibernate 多个连接动态变化

c# - 在单引号中设置参数值的Postgres准备语句错误