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, but I have read in the official postgresql documentation that other ways exist to do this function.
What would be the "correct" form, or was this form "correct"?
Example of the documentation that I could adapt for 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;