create or replace function inserta_tablas() returns setof record as $$
declare
res record;
i integer;
q text;
begin
i:= 0;
for res in select table_name from information_schema.tables
where table_schema not in ('information_schema', 'pg_catalog') and table_name <> 'u'
order by table_name
loop
raise notice 'insertando tabla: ----> %', res.table_name;
q:= 'insert into u select * from "' || res.table_name || '"' ;
execute q;
i:= i+1;
return next res;
end loop;
raise notice 'Tablas insertadas: %', i;
end;
$$ language plpgsql
Para ejecutar:
select * from une() as (tabl information_schema.sql_identifier);
Todas las tablas encontradas en la base de datos son insertadas a la tabla 'u'.
No hay comentarios.:
Publicar un comentario