[英]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.