我正在尝试创建包含文件路径的记录。使用驱动程序将插入到Postgres
启用了 UTF8 的数据库中。NpqSQL
我的表定义:
CREATE TABLE images
(
id serial,
file_location character varying NOT NULL
)
我的 SQL 语句,包括执行它的代码(归结为最低限度):
string sqlStatement = "INSERT INTO images (file_location) VALUES ('\\2010')";
NpgsqlConnection dbConnection = new NpgsqlConnection(connectionString);
dbConnection.Open();
NpgsqlCommand dbCommand = new NpgsqlCommand(sqlStatement , dbConnection);
int result = dbCommand.ExecuteNonQuery();
dbConnection.Close();
使用pgAdmin插入上述语句时,它工作正常。通过Visual Studio C#使用NpgSQL驱动程序,失败并出现以下异常:
"ERROR: 22021: invalid byte sequence for encoding \"UTF8\": 0x81"
正如Milen准确解释的那样,Postgres 将该语句解释为一个octal
数字 (\o201 == 0x81)。
正如Milen还描述E
的,路径的前面没有帮助。
快速回顾一下:为什么 NpqSQL 会停止我插入\\2010
?