我正在使用带有 C# 的 Npgsql 与我的 PostgreSQL 数据库进行通信。我的数据库中使用的所有名称都是大小写混合的,因此在查询中我确保在每个名称周围使用双引号。这是我发送查询的方式:
// construct an insert query
string insertQuery = "insert into \"Update\" (\"Vehicle\",\"Property\",\"Value\") " +
"values (" + vehicleNum.ToString() + ",\"" + propertyName +
"\",\"" + propertyValue + "\")";
// execute the query
NpgsqlCommand insertCommand = new NpgsqlCommand(insertQuery, conn);
insertCommand.ExecuteScalar();
通过插入断点并检查,我验证了字符串insertQuery
在发送之前看起来是这样的:
insert into "Update" ("Vehicle","Property","Value") values (12345,"EngineSpeed","50")
当我发送此查询时,PostgreSQL 给了我一个错误,该错误包含在一个 Npgsql 异常中,该异常指出:ERROR: 42703: column "EngineSpeed" does not exist
从我的查询来看,应该很明显EngineSpeed
不是列,而是列的值Property
,所以自然不可能存在具有该名称的列。那么为什么 PostgreSQL 会这样对待我的查询,我该如何解决这个问题呢?我的查询是否以错误的方式构建?