0
I have the following function :
create function sppreenchecombomunicipio(p_uf text) returns TABLE(MUNICIPIO
text, COD_MUNICIPIO int)
AS $$
begin
return query select tb_municipio.municipio, tb_municipio.cod_municipio from tb_municipio where UF = p_UF; end;
$$LANGUAGE plpgsql;
It is working, however I have read in the official documentation of postgresql that there are other ways to do this function.
What would be the "correct" form, or this form I posted is the "correct"?
Example of the documentation I could adapt to my case:
CREATE OR REPLACE FUNCTION get_all_foo() RETURNS SETOF foo
AS $BODY$
DECLARE
r foo%rowtype;
BEGIN
FOR r IN SELECT * FROM foo WHERE fooid > 0 LOOP
-- can do some processing here
RETURN NEXT r; -- return current row of SELECT
END LOOP;
RETURN;
END
$BODY$
LANGUAGE plpgsql;