2013/4/8 Marcelo da Silva <[email protected]>
> Pessoal estou tentando concatenar numa string o resultado de um select:
>
> email1, email2, email3, etc
>
> Sei pouca coisa em termos de funções em Postgres, criei a função abaixo
> pra isso.
> Mas está faltando o principal que é concatenar, vejam:
>
> CREATE OR REPLACE FUNCTION femailsclientes(integer)
> RETURNS character varying AS
> $BODY$
> declare
> result character varying;
> begin
>
> for result in select distinct email from mv_clientes_emails where
> (cod_id = $1)
> loop
> result = result || ',' || result;
> end loop;
> return result;
>
> end;
> $BODY$
> LANGUAGE plpgsql VOLATILE
> COST 100;
> ALTER FUNCTION femailsclientes(integer)
> OWNER TO postgres;
>
> Podem me ajudar?
>
> Obrigado
>
> Tente isso
CREATE OR REPLACE FUNCTION femailsclientes(integer)
RETURNS character varying AS
$BODY$
declare
--result character varying;
result record;
retorno character varying DEFAULT '';
begin
for result in select distinct email from mv_clientes_emails where
(cod_id = $1)
loop
--result = result || ',' || result;
IF retorno <> '' THEN
retorno := retorno||',';
END IF;
retorno := retorno||result.email;
end loop;
--return result;
RETURN retorno;
end;
$BODY$
LANGUAGE plpgsql VOLATILE;
[]s
Danilo
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral