![](/img/trans.png)
[英]Npgsql.PostgresException (0x80004005): 42883: operator does not exist: jsonb #> text
[英]npgsql, arrays and C# the operator does not exist: text[] = text
。 如果有人可以帮助我解决此问题,我将不胜感激
我正在开发使用npgsql和c#的应用程序,当我想从包含有元素数组的列的表中检索某些信息时,当我想使用这样的查询时,问题就开始了:
NpgsqlCommand cmd = new NpgsqlCommand("select * from book_editions", conn);
编译器将包含元素example({1st,2nd,3d})的列显示为“ Data.System.String [],因此我尝试通过使用参数来解决此问题。...如下所示。
NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;User Id=postgres; " +"Password=admin;Database=library_system;");
conn.Open();
//////string[] options = new string[] { "marketing", "m" }; already tried and failed
ArrayList l = new ArrayList();
l.Add("2th");
l.Add("3th");
NpgsqlParameter p = new NpgsqlParameter("parameterlist", NpgsqlTypes.NpgsqlDbType.Array | NpgsqlTypes.NpgsqlDbType.Text);
NpgsqlCommand cmd = new NpgsqlCommand("select * from book_editions where editions = any (:parameterlist)", conn);
//editions is the column which has the array of elements, its datatype is text
p.Value = l.ToArray();
cmd.Parameters.Add(p);
NpgsqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
Console.Write("{0} \n", dr[0].ToString());
Console.ReadKey();
conn.Close();
当我执行代码时, cmd.ExecuteReader
会引发此错误:
npgsql was unhandled
ERROR: 42883: el operador no existe: text[] = text
我得到以下句子作为提示。
宁根州的歌剧院商人与国会议员合影。 Puede ser necesario agregar转换为tipícitasde tipos。 (没有与名称和参数类型匹配的运算符,将需要添加显式类型转换
有人知道解决方案吗? :( :(我已经努力了。
更新:
var cmd = new NpgsqlCommand("select array_to_string(column, ', '),othercolumn,othercolumn from table",connection);
var l = new ArrayList();
l.Add("2th");
l.Add("3th");
cmd.Parameters.Add(new NpgsqlParameter("parameterlist", NpgsqlDbType.Array | NpgsqlDbType.Varchar));
cmd.Parameters[0].Value = l.ToArray();
var dr = cmd.ExecuteReader();
while (dr.Read())
Console.Write("{0} \n", dr[0].ToString());
Console.ReadKey();
conn.Close();
再试一次!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.