Subject Re: [Firebird-Architect] Re: Procedures vs functions
Author Dmitry Yemanov
"paulruizendaal" <pnr@...> wrote:
>
> In my opinion cursors should be a "first class" datatype. It should
> be possible to store cursors in variables and to pass cursors as
> parameters between procedures and functions. And yes, cursors should
> be a valid return type from a function.

I agree here.

> I would aim for a unification of functions and procedures, with PSQL
> procedures being generalized into (possibly void) functions.

This is a different thing than above. And AFAIU, it partially violates the
standard. What's the point in having both CREATE FUNCTION and CREATE
PROCEDURE if functions can behave as procedures and vice versa?

There was a similar discussion regarding executable vs selectable procedures
and the decision was that they should be clearly separated objects with
different invocation patterns, so we should have:

1) Executable procedures, invoked via EXECUTE <procedure name>
2) Selectable procedures, invoked via SELECT FROM <procedure name>

Functions add one more routine type:

3) Functions, invoked via <routine invocation> syntax of <value expression>

In order to support cursors, we could offer also:

3a) Functions, invoked via SELECT FROM TABLE (<function name>)

> We could
> keep the current PSQL procedure syntax with the following extensions:
> - selectable procedures with one return value can be used in
> expressions as functions
> - if a udf and a procedure have the same name, the udf is used
> - SUSPEND can take a cursor as optional argument; if it has such an
> argument it will automatically loop, returning cursor rows one by one

Personally, I don't support such an unification.


Dmitry