Fala Galera, alguém pode me mostrar onde ta errado nessa função por favor?

CREATE OR REPLACE FUNCTION teste() returns setof record as $$
DECLARE
tabela CURSOR IS select relname from pg_stat_user_tables order by relname;
linha record;
BEGIN
        OPEN tabela;
  FETCH tabela INTO linha;
  Execute 'copy (select row_to_json(t)from(select * from "'||linha||'") t)
to ''/Teste/teste''';
CLOSE tabela;

END;
$$
LANGUAGE plpgsql

select teste();


OBS: select relname from pg_stat_user_tables order by relname; retorna as
colunas com o nome das tabelas: Alunos, Usuarios e teste.

A ideia é converter para JSON e salvar o arquivo como nome teste, porém
quando executo aparace o seguinte erro:

ERRO:  relação "(Alunos)" não existe
LINE 1: copy (select row_to_json(t)from(select * from "(Alunos)") t)...
                                                      ^
QUERY:  copy (select row_to_json(t)from(select * from "(Alunos)") t) to
'/Teste/teste'
CONTEXT:  função PL/pgSQL teste() linha 9 em comando EXECUTE
********** Error **********

ERRO: relação "(Alunos)" não existe
SQL state: 42P01
Context: função PL/pgSQL teste() linha 9 em comando EXECUTE


Não estou conseguindo identificar, alguém poderia me ajudar por favor?


-- 
*Bruno da Cunha Felipe*





Enviado com MailTrack
<https://mailtrack.io/install?source=signature&lang=pt&[email protected]&idSignature=24>
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Responder a