Created
February 20, 2021 22:04
-
-
Save armando-couto/1014bd161f1ca705db10c2db3766589c to your computer and use it in GitHub Desktop.
Criando uma tabela temporário unificando de outras tabelas.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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