Re: [HACKERS] PL/pgSQL - for discussion (RETURN)

Started by Zeugswetter Andreasalmost 28 years ago4 messages
#1Zeugswetter Andreas
andreas.zeugswetter@telecom.at

Returning from the function

RETURN <expr>;

The function terminates and the value of <expr> will be
returned to the upper executor. The return value of a
function cannot be undefined. If control reaches the end
of the toplevel block of the function without hitting a
RETURN statement, a runtime error will occur.

1. I think we should allow functions/procedures, that don't have a return value.
(think about a proc that only does an update, why return anything except an error)
2. I think the RETURN will need a WITH RESUME, so a procedure can return more than one row.

create dba procedure "dns".getusers()
returning varchar(16), smallint;
define gotuser varchar(16);
define gotadmin smallint;
execute procedure checkadmin();
foreach select uname, admin into gotuser, gotadmin from passwd
return gotuser, gotadmin with resume;
end foreach;
end procedure;

Andreas

#2Noname
jwieck@debis.com
In reply to: Zeugswetter Andreas (#1)

Andreas wrote:

Returning from the function

RETURN <expr>;

The function terminates and the value of <expr> will be
returned to the upper executor. The return value of a
function cannot be undefined. If control reaches the end
of the toplevel block of the function without hitting a
RETURN statement, a runtime error will occur.

1. I think we should allow functions/procedures, that don't have a return value.
(think about a proc that only does an update, why return anything except an error)
2. I think the RETURN will need a WITH RESUME, so a procedure can return more than one row.

create dba procedure "dns".getusers()
returning varchar(16), smallint;
define gotuser varchar(16);
define gotadmin smallint;
execute procedure checkadmin();
foreach select uname, admin into gotuser, gotadmin from passwd
return gotuser, gotadmin with resume;
end foreach;
end procedure;

Yup. Looks nice. But the executor neither supports sets of
tuples nor single tuple to be returned from functions (except
for 'sql' language functions). I hacked around on that with
the PL/Tcl and even if I return a heap tuple or a tuple table
slot to the upper executor, it doesn't work :-(

Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#======================================== jwieck@debis.com (Jan Wieck) #

#3Jackson, DeJuan
djackson@cpsgroup.com
In reply to: Noname (#2)
RE: [HACKERS] PL/pgSQL - for discussion (RETURN)

Andreas wrote:

Returning from the function

RETURN <expr>;

The function terminates and the value of <expr> will

be

returned to the upper executor. The return value of

a

function cannot be undefined. If control reaches the

end

of the toplevel block of the function without hitting

a

RETURN statement, a runtime error will occur.

1. I think we should allow functions/procedures, that don't have a

return value.

(think about a proc that only does an update, why return anything

except an error)

2. I think the RETURN will need a WITH RESUME, so a procedure can

return more than one row.

create dba procedure "dns".getusers()
returning varchar(16), smallint;
define gotuser varchar(16);
define gotadmin smallint;
execute procedure checkadmin();
foreach select uname, admin into gotuser, gotadmin from passwd
return gotuser, gotadmin with resume;
end foreach;
end procedure;

Yup. Looks nice. But the executor neither supports sets of
tuples nor single tuple to be returned from functions (except
for 'sql' language functions). I hacked around on that with
the PL/Tcl and even if I return a heap tuple or a tuple table
slot to the upper executor, it doesn't work :-(

Jan

But what about Triggers?!.
DEJ

Show quoted text

--

#=====================================================================
=#
# It's easier to get forgiveness for being wrong than for being right.
#
# Let's break this rule - forgive me.
#
#======================================== jwieck@debis.com (Jan Wieck)
#

#4Noname
jwieck@debis.com
In reply to: Jackson, DeJuan (#3)

But what about Triggers?!.
DEJ

That's a completely different call interface. They return
a HeapTuple that can be a modified one or just NULL to skip
the whole action. But first I run for functions, then for
triggers.

Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#======================================== jwieck@debis.com (Jan Wieck) #