PL/PgSQL buglet / doc error

Started by Neil Conwayabout 23 years ago3 messages
#1Neil Conway
neilc@samurai.com

The 7.3 docs for the PL/PgSQL return statement say:

RETURN with an expression is used to return from a PL/pgSQL function
that does not return a set.

[...]

If you have declared the function to return void, then the expression
can be omitted, and will be ignored in any case.

However, that does not seem to be the case:

nconway=# select version(); version
------------------------------------------------------------------
PostgreSQL 7.4devel on i686-pc-linux-gnu, compiled by GCC 2.95.4
(1 row)

nconway=# create table bar (a int);
CREATE TABLE
nconway=# create or replace function test_func() returns void as
'begin insert into bar values (5); end;' language 'plpgsql';
CREATE FUNCTION
nconway=# select test_func();
WARNING: Error occurred while executing PL/pgSQL function test_func
WARNING: at END of toplevel PL block
ERROR: control reaches end of function without RETURN
nconway=# create or replace function test_func() returns void as
'begin insert into bar values (5); return; end;' language 'plpgsql';
CREATE FUNCTION
nconway=# select test_func();
test_func
-----------

(1 row)

Should this be implemented, or should the assertion that 'RETURN is
optional' be removed from the docs?

Cheers,

Neil

--
Neil Conway <neilc@samurai.com> || PGP Key ID: DB3C29FC

#2Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Neil Conway (#1)
Re: PL/PgSQL buglet / doc error

On 7 Nov 2002, Neil Conway wrote:

The 7.3 docs for the PL/PgSQL return statement say:

RETURN with an expression is used to return from a PL/pgSQL function
that does not return a set.

[...]

If you have declared the function to return void, then the expression
can be omitted, and will be ignored in any case.

...

Should this be implemented, or should the assertion that 'RETURN is
optional' be removed from the docs?

I'm not sure how you translated the above to return is optional. I'd
read it as the expression portion of the return statement is optional if
the function returns void. Thus you can say return; for the return
because the expression is optional.

#3Neil Conway
neilc@samurai.com
In reply to: Stephan Szabo (#2)
Re: PL/PgSQL buglet / doc error

Stephan Szabo <sszabo@megazone23.bigpanda.com> writes:

On 7 Nov 2002, Neil Conway wrote:

If you have declared the function to return void, then the expression
can be omitted, and will be ignored in any case.

I'm not sure how you translated the above to return is optional. I'd
read it as the expression portion of the return statement is optional if
the function returns void. Thus you can say return; for the return
because the expression is optional.

Woops :-)

There might be a case to be made for actually implementing this (not
requiring a blank RETURN at the end of a function body if the function
doesn't return anything), but the original "bug" is obviously a case
of my misreading the docs.

Sorry for the noise.

Cheers,

Neil

--
Neil Conway <neilc@samurai.com> || PGP Key ID: DB3C29FC