PostgreSQL – PLPGSQL function returns another function value

I have a function func1() that returns integers.

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.

all These works:

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;

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 696 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.