Here is postgresql running query with pg admin iii. (Below query working fine with pg admin and it is returning result set without any issue)
select * from pg_sp_getmainrates_11(9,10,array[[5,10,10,10],[30,20,15,16]]);
Here is parameter declaration of pg function.
CREATE OR REPLACE FUNCTION pg_sp_getmainrates_11(
IN fromcountryid integer,
IN tocountryid integer,
IN alldimensions_we_le_he_wi double precision[]
)
-- My logic is going here
But when passing array using C# code, it is returning error when executing the query.
Exeption attributes
Basemessage : syntax error at or near ","
ErrorSql : SELECT * FROM pg_sp_getmainrates_11(9,10,System.Double[,])
Here is my C# code.
double[,] codes = new double[,]
{
{ 5,10,10,10},{ 30,20,15,16}
};
string quy = "pg_sp_getmainrates_11(" + FromCountryId +
"," + ToCountryId +
"," + codes + ")";
NpgsqlCommand command = new NpgsqlCommand(quy, conn);
command.CommandType = CommandType.StoredProcedure;
NpgsqlDataReader dr = command.ExecuteReader();
I need a small direction to pass an array (like above) to my postgresql function.
{{},{}}your postgresql array is:[[],[]]. No one will convert it for you if you won't tell the compiler to do such conversion. More over postgresql does not treat the same forarrayandint[]ornumeric[]. you may call them the same but they are not the same. So your definition for array in c# as double[,] needs to be casted for the proper type in postgresql.