Skip to content

Instantly share code, notes, and snippets.

@armando-couto
Created February 20, 2021 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save armando-couto/1014bd161f1ca705db10c2db3766589c to your computer and use it in GitHub Desktop.
Save armando-couto/1014bd161f1ca705db10c2db3766589c to your computer and use it in GitHub Desktop.
Criando uma tabela temporário unificando de outras tabelas.
DROP FUNCTION tabela_temporaria();
CREATE OR REPLACE FUNCTION tabela_temporaria()
RETURNS TABLE (id bigint, nome character varying, cpf character varying) AS
$func$
DECLARE
_row RECORD;
BEGIN
FOR _row IN (SELECT tablename as name FROM pg_catalog.pg_tables WHERE tablename LIKE 'tabela_temporarias%') LOOP
return query EXECUTE ' SELECT id, nome, cpf
FROM ' || _row.name || ' os ';
END LOOP;
END
$func$ LANGUAGE plpgsql;
select id, nome, cpf FROM tabela_temporaria() LIMIT 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment