I need to write a function in Postgresql where the function will return a table with three columns. These three columns will be populated from three different queries. I want to know how to club these three queries in a single function.
CREATE OR REPLACE FUNCTION ytd(MMYY character varying, MMYY1 character varying)
RETURNS TABLE(name character varying, ratio bigint, ratio1 bigint) AS
$BODY$
BEGIN
RETURN query
SELECT col1 as name from t1,
Select col2 as ratio from t2,
Select col3 as ratio1 from t3
END
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100
ROWS 1000;
ALTER FUNCTION ydt2(MMYY character varying, MMYY1 character varying)
OWNER TO postgres;
Same parameter will be passed in each sql
FUNCTIONwith aPROCEDUREand make use of three output parameters.