How do you call a pg procedure with parameters from C#?
the 100 examples and other related posts do NOT work. i.e. (How would I call a PostgreSQL 13 stored procedure from C#?)
here’s my super simple example:
table
(col1 integer,
col2 character varying(20) )
proc
create procedure proc1 (num int, str varchar(20))
language plpgsql
as $$
begin
insert into test1 (col1, col2) VALUES (num, str);
commit;
end;$$;
code
using var cmd = new NpgsqlCommand("CALL proc1()", _con);
cmd.Parameters.AddWithValue("num", NpgsqlDbType.Integer, 2);
cmd.Parameters.AddWithValue("str", NpgsqlDbType.Varchar, "string");
cmd.ExecuteNonQuery();
exception: Npgsql.PostgresException: ‘42883: procedure proc1() does not exist
POSITION: 6′
I also made a proc2 that has NO parameters and I’m able to call that one just fine. I also tried several variant to “CALL proc1()” like “CALL proc1(num, str)” but those exceptions make even less sense as pg can’t tell the difference between a parameter and a column: “Npgsql.PostgresException: ‘42703: column “num” does not exist”