On 16-11-2015 11:12, Euler Taveira wrote:
> On 16-11-2015 08:31, Bruno Felipe wrote:
>> Mais onde ele ficaria melhor para ler e converter tabela a tabela?
>>
> Eu não entendi... mas o laço ficaria:
> 
> CREATE OR REPLACE FUNCTION teste() RETURNS SETOF record
>     LANGUAGE plpgsql
>     AS $$
> DECLARE
> tabela CURSOR IS SELECT relname FROM pg_stat_user_tables ORDER BY relname;
> BEGIN
>     FOR i IN tabela LOOP
>         EXECUTE 'COPY (SELECT row_to_json(t) FROM (SELECT * FROM ' ||
> quote_ident(i.relname) || ') t) TO ''/tmp/' || i.relname || '.sql''';
>     END LOOP;
> END;
> $$;
> 

Porque aquela sub-query? Apenas assim não resolve?

EXECUTE 'COPY (SELECT row_to_json(t) FROM '||quote_ident(i.relname)||'
t) TO ''/tmp/' || i.relname || '.sql''';

Att,

-- 
   Fabrízio de Royes Mello         Timbira - http://www.timbira.com.br/
   PostgreSQL: Consultoria, Desenvolvimento, Suporte 24x7 e Treinamento

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Responder a