Use string[][] with ngpsql

孤人 提交于 2019-12-11 10:13:27

问题


Its not supported? I get an exception when trying to insert data with command parameter set as:

var parameter = ((IDbDataParameter)cmd.Parameters[index]);
var list = (string[][])value;
parameter.Value = list;

With message

System.NotSupportedException: This .NET type is not supported in Npgsql or your PostgreSQL: System.String[][]

I'm using PostgreSQL 9.4 and created a column with type text[][]. Since text[] maps to string[] without any issues, I can't see a reason why two dimensional arrays are not working.


回答1:


There is no data type text[][] in Postgres. Syntax variants indicating multiple array dimensions are tolerated for documentation, but internally all of those are mapped to the same (and only) array type that works for any number of dimensions: text[]. Try string[] in your .net declaration.

You don't have to take my word, test yourself:

SELECT pg_typeof(NULL::text[][])            AS type1
     , pg_typeof('{a,b}'::text[][])         AS type2
     , pg_typeof('{{{a,b},{c,d}}, {{a,b},{c,d}}}'::text[][][][][]) AS type3;


 type1  | type2  | type3
--------+--------+--------
 text[] | text[] | text[]

Related:

  • mapping postgresql text[][] type and Java type


来源:https://stackoverflow.com/questions/34314338/use-string-with-ngpsql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!