Lists: | pgsql-hackers |
---|
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | pgsql-hackers(at)postgreSQL(dot)org |
Subject: | Should we still require RETURN in plpgsql? |
Date: | 2005-04-05 06:28:23 |
Message-ID: | 10266.1112682503@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
As of CVS tip, plpgsql handles output parameters, in the style
CREATE FUNCTION sum_n_product(x int, y int, OUT sum int, OUT prod int) AS $$
BEGIN
sum := x + y;
prod := x * y;
RETURN;
END;
$$ LANGUAGE plpgsql;
The RETURN statement is kinda useless in this example, but it is still
required, because we don't allow control to fall off the end of a
plpgsql function without causing an error.
I am thinking we should allow exit by falling off the end of the
function when (a) it has output parameter(s), or (b) it is declared
"RETURNS void". Comments?
How does Oracle's PL/SQL handle this?
regards, tom lane
From: | Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Should we still require RETURN in plpgsql? |
Date: | 2005-04-05 06:40:22 |
Message-ID: | 425232D6.1030606@familyhealth.com.au |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
> I am thinking we should allow exit by falling off the end of the
> function when (a) it has output parameter(s), or (b) it is declared
> "RETURNS void". Comments?
I agree - makes sense.
Chris
From: | Dennis Bjorklund <db(at)zigo(dot)dhs(dot)org> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | pgsql-hackers(at)postgreSQL(dot)org |
Subject: | Re: Should we still require RETURN in plpgsql? |
Date: | 2005-04-05 07:04:30 |
Message-ID: | Pine.LNX.4.44.0504050900340.16409-100000@zigo.dhs.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Tue, 5 Apr 2005, Tom Lane wrote:
> CREATE FUNCTION sum_n_product(x int, y int, OUT sum int, OUT prod int) AS $$
> BEGIN
> sum := x + y;
> prod := x * y;
> RETURN;
> END;
> $$ LANGUAGE plpgsql;
>
> The RETURN statement is kinda useless in this example, but it is still
> required, because we don't allow control to fall off the end of a
> plpgsql function without causing an error.
>
> I am thinking we should allow exit by falling off the end of the
> function when (a) it has output parameter(s), or (b) it is declared
> "RETURNS void". Comments?
The above code example do not have any RETURNS clause, does that mean that
it defaults to RETURNS void?
I don't see what (a) has to do with anything. The return value is
independent of in/out:ness of the parameters, isn't it?
--
/Dennis Björklund
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Dennis Bjorklund <db(at)zigo(dot)dhs(dot)org> |
Cc: | pgsql-hackers(at)postgreSQL(dot)org |
Subject: | Re: Should we still require RETURN in plpgsql? |
Date: | 2005-04-05 07:43:39 |
Message-ID: | 10862.1112687019@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Dennis Bjorklund <db(at)zigo(dot)dhs(dot)org> writes:
> On Tue, 5 Apr 2005, Tom Lane wrote:
>> CREATE FUNCTION sum_n_product(x int, y int, OUT sum int, OUT prod int) AS $$
>> BEGIN
>> sum := x + y;
>> prod := x * y;
>> RETURN;
>> END;
>> $$ LANGUAGE plpgsql;
> The above code example do not have any RETURNS clause, does that mean that
> it defaults to RETURNS void?
No, it effectively "RETURNS record", where the particular record type is
implied by the set of output parameters. See my previous proposal.
regards, tom lane
From: | Terry Yapt <yapt(at)NOtechSAPMnovell(dot)com> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Should we still require RETURN in plpgsql? |
Date: | 2005-04-05 07:51:05 |
Message-ID: | udg451tcop8o779h9vmi3l9gdgu7tuvpij@4ax.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Hello...
On Tue, 05 Apr 2005 02:28:23 -0400, tgl(at)sss(dot)pgh(dot)pa(dot)us (Tom Lane)
wrote:
>
>How does Oracle's PL/SQL handle this?
On ORACLE a FUNCTION MUST return a value. If the FUNCTION doesn't
return a value Oracle give a 'hint' on FUNCTION compilation and error
on SELECT function invocation: ORA-06503.
When we don't want to return any result on ORACLE we must use
PROCEDURE statement instead of FUNCTION.
Example:
========
SQL> CREATE OR REPLACE FUNCTION F_test RETURN NUMBER IS
2 BEGIN
3 NULL;
4 END F_TEST;
5 /
Function created.
SQL> SELECT F_TEST FROM DUAL;
SELECT TUZSA.F_TEST FROM DUAL
*
ERROR at line 1:
ORA-06503: PL/SQL: Function returned without value
ORA-06512: at "F_TEST", line 3
SQL>
========
Greetings.
From: | Robert Treat <xzilla(at)users(dot)sourceforge(dot)net> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Dennis Bjorklund <db(at)zigo(dot)dhs(dot)org>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Should we still require RETURN in plpgsql? |
Date: | 2005-04-05 13:01:19 |
Message-ID: | 1112706080.26170.278.camel@camel |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Tue, 2005-04-05 at 03:43, Tom Lane wrote:
> Dennis Bjorklund <db(at)zigo(dot)dhs(dot)org> writes:
> > On Tue, 5 Apr 2005, Tom Lane wrote:
> >> CREATE FUNCTION sum_n_product(x int, y int, OUT sum int, OUT prod int) AS $$
> >> BEGIN
> >> sum := x + y;
> >> prod := x * y;
> >> RETURN;
> >> END;
> >> $$ LANGUAGE plpgsql;
>
> > The above code example do not have any RETURNS clause, does that mean that
> > it defaults to RETURNS void?
>
> No, it effectively "RETURNS record", where the particular record type is
> implied by the set of output parameters. See my previous proposal.
>
While it is useless in this example, istm it only makes things more
confusing to require return in some cases but not in others. Is there
some technical advantage to dropping it?
Robert Treat
--
Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Robert Treat <xzilla(at)users(dot)sourceforge(dot)net> |
Cc: | Dennis Bjorklund <db(at)zigo(dot)dhs(dot)org>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Should we still require RETURN in plpgsql? |
Date: | 2005-04-05 15:22:21 |
Message-ID: | 13728.1112714541@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Robert Treat <xzilla(at)users(dot)sourceforge(dot)net> writes:
> While it is useless in this example, istm it only makes things more
> confusing to require return in some cases but not in others. Is there
> some technical advantage to dropping it?
It's about the same either way as far as the code is concerned. But
I've only written a dozen or so plpgsql functions using OUT parameters,
and I've already found having to write a useless RETURN to be tedious
(not to mention that I forgot it a couple times). I don't think I'll be
the last one complaining if we leave in the requirement.
Basically the requirement exists to make sure you don't forget to define
the return value. But when you're using OUT parameters, the existence
of a RETURN statement has nothing to do with defining the return value.
regards, tom lane
From: | Oleg Bartunov <oleg(at)sai(dot)msu(dot)su> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, Dennis Bjorklund <db(at)zigo(dot)dhs(dot)org>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Should we still require RETURN in plpgsql? |
Date: | 2005-04-05 15:33:51 |
Message-ID: | Pine.GSO.4.62.0504051932560.15865@ra.sai.msu.su |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Tue, 5 Apr 2005, Tom Lane wrote:
> Robert Treat <xzilla(at)users(dot)sourceforge(dot)net> writes:
>> While it is useless in this example, istm it only makes things more
>> confusing to require return in some cases but not in others. Is there
>> some technical advantage to dropping it?
>
> It's about the same either way as far as the code is concerned. But
> I've only written a dozen or so plpgsql functions using OUT parameters,
> and I've already found having to write a useless RETURN to be tedious
> (not to mention that I forgot it a couple times). I don't think I'll be
> the last one complaining if we leave in the requirement.
>
> Basically the requirement exists to make sure you don't forget to define
> the return value. But when you're using OUT parameters, the existence
> of a RETURN statement has nothing to do with defining the return value.
what if not require RETURN iff OUT parameter is defined ?
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)
>
Regards,
Oleg
_____________________________________________________________
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: oleg(at)sai(dot)msu(dot)su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Oleg Bartunov <oleg(at)sai(dot)msu(dot)su> |
Cc: | Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, Dennis Bjorklund <db(at)zigo(dot)dhs(dot)org>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Should we still require RETURN in plpgsql? |
Date: | 2005-04-05 15:51:21 |
Message-ID: | 14025.1112716281@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Oleg Bartunov <oleg(at)sai(dot)msu(dot)su> writes:
> what if not require RETURN iff OUT parameter is defined ?
That's what I'm suggesting ;-)
regards, tom lane