You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Npgsql doesn't support pass parameters by name to functions #305
Table
CREATE TABLE "Image"
(
"Name" character varying(50),
"Description" character varying(250),
"ImageID" serial NOT NULL,
CONSTRAINT pk_image PRIMARY KEY ("ImageID")
)
I have the next function
CREATE OR REPLACE FUNCTION "ImageInsert"(pname character varying, pdescription character varying)
RETURNS "Image" AS
$BODY$
DECLARE
res "Image"%ROWTYPE;
pImageID "Image"."ImageID"%type;
BEGIN
pImageID:= nextval('"Image_ImageID_seq"');
insert into "Image"("ImageID", "Name", "Description") values(pImageID, pName, pDescription);
select * into res from "Image" where "ImageID" = pImageID;
return res;
END;
$BODY$
LANGUAGE 'plpgsql'
A look at the Postgresql docs shows that Postgresql itself doesn't support named parameters, only positional ones. Note that supporting named parameters isn't mandated by the ADO.NET contract, different data providers support different things.
Note that Postgresql's ParameterDescription message, which returns information on the parameters of a parsed query, doesn't return names. This makes it pretty much impossible to do named parameters unless I'm missing something.
Will keep open for a bit more for comments, then close.
Even though not stated in the issue, I assume this refers only to the case where CommandType is set to StoredProcedure?
If we leave everything as it is, we should add in the documentation, that when having CommandType set to StoredProcedure, the parameters in the parameter collection must be in the same order as in the function declaration.
Ah, I misunderstood that entirely. Thanks for commenting.
So this would be a purely Npgsql-internal feature to generate the correct SELECT * FROM function_call(...) query text with the Postgresql named notation. That's definitely doable.
Note that SqlClient really does support named parameters for non-stored procedures - in fact it seems to be the only way to specify query parameters. And this we can't provide...
Ah, I misunderstood that entirely. Thanks for commenting.
So this would be a purely Npgsql-internal feature to generate the correct SELECT * FROM function_call(...) query text with the Postgresql named notation. That's definitely doable.
Note that SqlClient really does support named parameters for non-stored procedures - in fact it seems to be the only way to specify query parameters. And this we can't provide...
But this is only for referring to what parameter holder, right? I.e what we support right now with the query rewrite process?
Well, the way I understand it there are two different problems: function calls and parameterized queries. In function calls the user doesn't specify placeholders in the query text: they just specify the function name. Npgsql then needs to generate the SQL with the placeholders. What we're discussing in this issue is only related to how Npgsql generates the SQL from the user's input - it doesn't touch the question of what happens in parameterized queries (where placeholders are exposed to the user).
That's right. It's a feature for StoredProcedure only.
Of course the specifics need to be worked out. Note that Postgresql supports mixed notation, where positional arguments come first, followed by named arguments. We'd have to implement it properly etc.
Guys, any updates on this? I'm moving my backend from SQL to postgres and suffering a lot since I should recheck all 100+ backend schema to be matching DB functions' params order.
changed the title [-][#1010781] Npgsql doesn't support pass parameters by name[/-][+]Npgsql doesn't support pass parameters by name to functions[/+]on Aug 23, 2015
I changed so that parameters with a name are now passed using their name. Parameters without names entered by the user will now be sent normally using Positional Notation. In case there are some parameters with names and some without, Mixed Notation is used.
I hope this won't affect people that has previously set names that don't correspond to the PostgreSQL parameter name...
Activity
roji commentedon Oct 28, 2014
A look at the Postgresql docs shows that Postgresql itself doesn't support named parameters, only positional ones. Note that supporting named parameters isn't mandated by the ADO.NET contract, different data providers support different things.
Note that Postgresql's ParameterDescription message, which returns information on the parameters of a parsed query, doesn't return names. This makes it pretty much impossible to do named parameters unless I'm missing something.
Will keep open for a bit more for comments, then close.
Emill commentedon Oct 28, 2014
Even though not stated in the issue, I assume this refers only to the case where CommandType is set to StoredProcedure?
If we leave everything as it is, we should add in the documentation, that when having CommandType set to StoredProcedure, the parameters in the parameter collection must be in the same order as in the function declaration.
But, see section "4.3.2 Using Named Notation" http://www.postgresql.org/docs/9.1/static/sql-syntax-calling-funcs.html. It's actually possible to call a function with named parameters.
roji commentedon Oct 28, 2014
Ah, I misunderstood that entirely. Thanks for commenting.
So this would be a purely Npgsql-internal feature to generate the correct SELECT * FROM function_call(...) query text with the Postgresql named notation. That's definitely doable.
Note that SqlClient really does support named parameters for non-stored procedures - in fact it seems to be the only way to specify query parameters. And this we can't provide...
Emill commentedon Oct 28, 2014
But this is only for referring to what parameter holder, right? I.e what we support right now with the query rewrite process?
roji commentedon Oct 28, 2014
Well, the way I understand it there are two different problems: function calls and parameterized queries. In function calls the user doesn't specify placeholders in the query text: they just specify the function name. Npgsql then needs to generate the SQL with the placeholders. What we're discussing in this issue is only related to how Npgsql generates the SQL from the user's input - it doesn't touch the question of what happens in parameterized queries (where placeholders are exposed to the user).
Emill commentedon Oct 28, 2014
Yes. So this means the named parameter notation approach would work, since we do this only when having CommandType set to StoredProcedure?
roji commentedon Oct 28, 2014
That's right. It's a feature for StoredProcedure only.
Of course the specifics need to be worked out. Note that Postgresql supports mixed notation, where positional arguments come first, followed by named arguments. We'd have to implement it properly etc.
shimole commentedon Aug 13, 2015
Guys, any updates on this? I'm moving my backend from SQL to postgres and suffering a lot since I should recheck all 100+ backend schema to be matching DB functions' params order.
roji commentedon Aug 13, 2015
I'm sorry, with everything that's happening right now in Npgsql (v3, EF7...) there just hasn't been any spare time for this yet...
[-][#1010781] Npgsql doesn't support pass parameters by name[/-][+]Npgsql doesn't support pass parameters by name to functions[/+]Emill commentedon Aug 23, 2015
I changed so that parameters with a name are now passed using their name. Parameters without names entered by the user will now be sent normally using Positional Notation. In case there are some parameters with names and some without, Mixed Notation is used.
I hope this won't affect people that has previously set names that don't correspond to the PostgreSQL parameter name...