I’m encountering an unusual error while trying to invoke a PostgreSQL stored procedure from my C# application using Npgsql. The error message reads Backend sent unrecognized response type: o.
Here’s my PostgreSQL function:
CREATE OR REPLACE FUNCTION Fifty(field_a bigint, field_b bigint, field_c decimal, field_d decimal, field_e bigint)
RETURNS void AS $$
DECLARE variableA bigint;
BEGIN
IF (field_b != 0) THEN
INSERT INTO table_a
SELECT fields FROM table_a
WHERE field_a = a AND field_b = b AND field_c = c;
SELECT field_d INTO table FROM table_a
WHERE field_a = a AND field_b = b;
UPDATE tb_history SET
field_a = a,
value = b,
his_value = d * 0.02,
his_deb = 0.08,
his_id = field_a
WHERE field_a = a AND his_deb = b AND his_id = c;
DELETE FROM table_a WHERE field_a = a AND field_b = b AND field_c = c;
ELSE
DELETE FROM table_d WHERE field_a IN (SELECT ...);
DELETE FROM table_d WHERE field_a IN (SELECT ...);
DELETE FROM table_e WHERE field_a = a AND field_b = b AND field_c = c;
DELETE FROM table_a WHERE field_a = a AND field_b = b AND field_c = c;
END IF;
END
$$ LANGUAGE plpgsql;
In my C# code, I’m using the following:
using (NpgsqlCommand command = new NpgsqlCommand())
{
command.Connection = this.conn;
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "Fifty";
var parm = command.CreateParameter();
parm.ParameterName = "...";
parm.DbType = DbType.Int64;
parm.Value = ...;
command.Parameters.Add(parm);
// Additional parameters setup
command.ExecuteNonQuery();
}
Interestingly, the function executes perfectly in pgAdmin without any issues, so I suspect the problem may stem from the return type being void. I’m unsure what adjustments I need to make for successful execution.