0

I would like to know if it is possible to execute a store function using NpgsqlBatch having NpgsqlBatchCommand with parameter?

I am using Npgsql 8.0.4

Basically, it tried the following:

sql = $"SELECT {FunctionName}($1, $2)";
foreach (var value in values)
{

    var cmd = new NpgsqlBatchCommand(sql)
    {
        Parameters =
        {
            new NpgsqlParameter {NpgsqlDbType = NpgsqlDbType.someType, Value = value.Item1},
            new NpgsqlParameter {NpgsqlDbType = NpgsqlDbType.someType2, Value = value.Item2)},
        }
    };
    batch.BatchCommands.Add(cmd);
}

batch.Prepare();
var reader = batch.ExecuteReader();

but the reader is empty.

I made it worked for function inserting but not on function selecting

Any ideas?

4
  • Yes, this is supposed to work - please post a fully runnable minimal code sample that reproduces the problem. Commented Oct 13, 2024 at 20:02
  • I found out another thread on which you explain a function should not return refcursor. I bet the issue is coming from that :) Commented Oct 14, 2024 at 13:32
  • Yes, probably - and this shows why it is important to always post the full information when posting question; there's no way of knowing in your above post that the function returns a refcursor. Commented Oct 21, 2024 at 6:36
  • You are right. Your last comment also show how it is important to stay indulgent with posters. There are a lot of different profiles in here, beginners who might not always recognize important information, employees following strict company policies and especially kind helpers who take on their time to provide benevolent answers. Commented Nov 1, 2024 at 14:02

0

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.