问题
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 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[][]
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