Re: [Info-Ingres] Enhancement to DB procedures -
01-08-2009
, 05:19 AM
Hi Marty,
Why not "create function" ?
Do we need the "callproc" keyword ?
Can we have positional parameters ?
I'd prefer to see the RETURN keyword before the AS
create function volume (
X integer default 0,
Y integer default 0,
Z integer default 0
) returns varchar(5) as
begin
declare HowBig varchar(5)
if X * Y * Z >=100
set HowBig = 'big'
elseif X * Y * Z = 0
set HowBig = 'tiny'
else
set HowBig = 'small'
return HowBig
end
select volume(X=height,Y=width,Z=depth), .... from room_dimensions..
or
select volume(height,width,depth), .... from room_dimensions..
Of course I would never use a function in a where clause because that leads
to table scans.
-----Original Message-----
From: info-ingres-bounces (AT) kettleriver...ting (DOT) com
[mailto:info-ingres-bounces (AT) kettleriverconsulting (DOT) com]On Behalf Of Martin
Bowes
Sent: Thursday, 8 January 2009 8:44 PM
To: info-ingres (AT) kettleriverconsulting (DOT) com
Subject: [Info-Ingres] Enhancement to DB procedures
Hi All,
I've been tossing up an idea here and was wondering what people think.I'm
basically trying to allow user defined functions (in a limited form) without
the hassle of having to go through the full C type function create and link.
It seems to me that the simplest way to do this is to define a db
procedure with a specified return type.it can be any valid ingres data type.
The procedure can only raise an error or return something of that type. The
procedure has access to all the normal 4GL stuff a procedure can access. So
these won't be as powerful as full blown OME functions, but will allow
people to make function like procedures.
Because the procedure has a gaurunteed return type we could then call the
procedure from anywhere we can use a column name. We can use the existing
callproc or execute procedure syntax.
What I would envisage is something like.
create procedure my_proc(
p1 integer not null,
p2 integer not null,
p3 integer not null
) as
return integer not null
declare
msg varchar(256);
total integer not null;
begin
if (p3 = 0) then
msg = 'p3 may not be zero you goose!';
raise error 9999 msg;
endif;
total = (p1 +p2)*p3;
return total;
end;
select .whatever. from .
where callproc my_proc (p1=a, p2=b, p3=c) = 3;
or.. select a,b, callproc my_proc(p1=a, p2=b, p3=c);
What do people think of this?
Martin Bowes |