I want to write another function func2 (mode integer), which can return func1()reults Or do more things. The return value of func1() is INTEGER type.
Things like this:
CREATE OR REPLACE FUNCTION func2(mode integer )
RETURNS integer AS
$$
begin
if mode=1 then
return func1(); - NOT plpgsql syntax
end if;< br />
more stuff .....
return 2;
end
$$
LANGUAGE plpgsql VOLATILE
My question is how do I return func1();?
I know I can do it:
select func1() into temp;
return temp;
But If there is a more elegant way to do this, then I am thinking.
Option 1:
CREATE OR REPLACE FUNCTION func2(mode integer)
RETURNS integer AS
$BODY$
DECLARE
_result integer;
BEGIN
_result = 2;
IF mode=1 THEN
_result = func1();
END IF;
--more stuff .....
RETURN _result;
END
$BODY$
LANGUAGE plpgsql VOLATILE COST 100;
Option 2:
CREATE OR REPLACE FUNCTION func2(mode integer)
RETURNS integer AS
$BODY $
BEGIN
IF mode=1 THEN
RETURN func1();
END IF;
--more stuff .....
RETURN 2;
END
$BODY$
LANGUAGE plpgsql VOLATILE COST 100;
I have a function func1() returns an integer.
I want to write another function func2 (mode integer), which You can return func1()reults or do more things. The return value of func1() is of type INTEGER.
Such things:
CREATE OR REPLACE FUNCTION func2(mode integer)
RETURNS integer AS
$$
begin
if mode=1 then
return func1(); - NOT plpgsql syntax
end if;
more stuff .....
return 2;
end
$$
LANGUAGE plpgsql VOLATILE< /pre>My question is how do I return func1();?
I know I can do it:
select func1() into temp;
return temp;But If there is a more elegant way to do this, then I am thinking.
All these work:
Option 1:
CREATE OR REPLACE FUNCTION func2(mode integer)
RETURNS integer AS
$BODY$
DECLARE
_result integer;
BEGIN
_result = 2;
IF mode=1 THEN
_result = func1();
END IF;
--more stuff .....
RETURN _result;
END
$BODY$
LANGUAGE plpgsql VOLATILE COST 100;Options 2:
CREATE OR REPLACE FUNCTION func2(mode integer)
RETURNS integer AS
$BODY$
BEGIN
IF mode =1 THEN
RETURN func1();
END IF;
--more stuff .....
RETURN 2;
END
$BODY$
LANGUAGE plpgsql VOLATILE COST 100;