2

I'm working with code I'm converting to Pgsql working with .NET. I want to call a stored function that has several parameters, but I'd like to bind the parameters by name, like so:

NpgsqlCommand command = new NpgsqlCommand("\"StoredFunction\"", _Connection)
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("param2", value2);
command.PArameters.Add("param1", value1);

Attempts to do this so far look for a function with parameter types matching in the order in which I added the parameters to the collection, not by name.

Is it possible for Npgsql to bind parameters to stored functions by name?

2 Answers 2

3

Currently Npgsql doesn't support pass parameters by name. Although it supports receiving out parameter values by name.

Would you mind to fill a bug report about that? So we can track and implement it.

Sign up to request clarification or add additional context in comments.

2 Comments

Having trouble reporting this. I've registered on the site but reporting the bug isn't working.
Would you mind to try filling the bug report again. Thanks in advance.
3

Unfortunately it does not work with store procedure (CommandType.StoredProcedure).

It does with SQL-text command (CommandType.Text). You can use :paramname, plus I think in the latest version you can use parameters.addwithvalue(":paramname", param).

You can also use @paramname with the latest version (like MS Sql Server).

Read section "Using parameters in a query " of this manual for an answer to your original question - but remember what I said above to make your life easier.

3 Comments

testing with the version of Npgsql available in Q1 2013, I find that the provider seems to support only positional mode parameter passing to functions on the server when client-side the command is in CommandType.StoredProcedure mode. The order in which the parameters are added to the Command's Parameters collection is the order in which they're provided.
I didn't test with StoredProcedure, it does work with Text though.
The link to the manual does not work anymore, do you know where it has moved to?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.