1

Version 7.0 of the Npgsql dotnet client interface to PostgreSQL databases introduced a breaking change in which CommandType.StoredProcedure now calls a PostgreSQL PROCEDURE rather than a FUNCTION.

Our application uses generic code that works with several database vendors. Generic code uses objects like DbCommand and DbConnection and DbProviderFactories. Every database call in our vendor independent app is a call to a stored procedure. About 1/2 the stored procedures return results as a record set from a SELECT statement.

I know that the Npgsql client can be forced back to legacy behaviour where it calls a PostgreSQL FUNCTION instead of a PROCEDURE. See: Stored functions and procedures

But, from a go forward perspective, is there a way (what is the plan) for having a PostgreSQL PROCEDURE return a record set - consistent with other database vendors?

Is there some syntax variation on OUT parameters that can return a record set in a PROCEDURE?

Here is a sample PROCEDURE that DOES NOT return any data through Npgsql...

CREATE OR REPLACE PROCEDURE public."AttributeSelect"()
LANGUAGE 'sql'
AS $$
   SELECT "Id" FROM "Attribute";
$$;
1
  • Note that there's no real need to use CommandType.StoredProcedure. You can easily invoke a stored procedure via CALL, and a stored function via SELECT * FROM. The same is typically the case in other databases. Commented Sep 27, 2023 at 10:49

1 Answer 1

2

No, there is currently (Postgres 16) no way to return a set from a PROCEDURE. You can return a single row with OUT or INOUT parameters. See:

To return a set, use a FUNCTION. A so-called "set-returning function", a.k.a. "table-function". Related:

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

Comments

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.