I tried this code:
CREATE OR REPLACE FUNCTION public.t4(in iid int, OUT n1 text, OUT n2 text)
LANGUAGE plpgsql
AS $function$
BEGIN
SELECT DISTINCT n1=l.name, n2=l.comment from public.languages l where l.id=iid;
END;
$function$;
NpgsqlConnection connection = new NpgsqlConnection(ConString);
connection.Open();
NpgsqlCommand cmd = new NpgsqlCommand("SELECT * from public.t4()", connection);
cmd.Parameters.Add(new NpgsqlParameter("iid", DbType.Int32) { Direction = ParameterDirection.Input });
cmd.Parameters[0].Value = 18;
cmd.Parameters.Add(new NpgsqlParameter("n1", DbType.String) { Direction = ParameterDirection.Output });
cmd.Parameters.Add(new NpgsqlParameter("n2", DbType.String) { Direction = ParameterDirection.Output });
cmd.ExecuteNonQuery();
t1.Text = cmd.Parameters[1].Value.ToString();
t2.Text = cmd.Parameters[2].Value.ToString();
And I got an error:
Npgsql.PostgresException: '42883: function public.t4() does not exist.
What am I doing wrong?
function public.t4()does not exist, butpublic.t4(in iid int, OUT n1 text, OUT n2 text)does. I don't any placeholders in the query for the parameters you are trying to add. See here stackoverflow.com/questions/54691579/… fro examples.