I have two similar functions with the same table as an outcome and I would like to create function to choose which of those will be execute.
My functions are create from the code like below - function_a and function_b:
CREATE OR REPLACE FUNCTION function_a(sys_id integer)
RETURNS TABLE (
col_1 text,
col_2 text,
col_3 text) AS $$
(...)
END; $$
LANGUAGE 'plpgsql';
And I would like to get something like this (this code doesn't work but I think it expresses my intention):
CREATE OR REPLACE FUNCTION choose_function(system text, sys_id integer)
RETURNS TABLE (
col_1 text,
col_2 text,
col_3 text) AS $$
BEGIN
IF system = 'A' THEN RETURN
(select * from function_a(sys_id));
ELSEIF system = 'B' THEN RETURN
(select * from function_b(sys_id));
END IF;
END; $$
LANGUAGE 'plpgsql';
I receive an error:
ERROR: RETURN cannot have a parameter in function returning set
and hint:
HINT: Use RETURN NEXT or RETURN QUERY.
But use RETURN QUERY cause that I receive empty table or rather headers only and use RETURN NEXT give me also an error: ERROR: RETURN NEXT cannot have a parameter in function with OUT parameters.
Is it possible to do what I need?
return query select ...- a_horse_with_no_name