Created
July 30, 2016 21:51
-
-
Save sebawebber/1b9b588ba2115fe3f47147678c89895a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| -- criação da função | |
| CREATE OR REPLACE FUNCTION fnc_roda_selects() | |
| RETURNS SETOF RECORD | |
| AS $$ | |
| DECLARE | |
| rResult RECORD; | |
| BEGIN | |
| -- tenta buscar dados na tabela com um filtro especifico | |
| PERFORM * FROM dw.dim_tempo; | |
| IF FOUND THEN | |
| FOR rResult IN | |
| SELECT | |
| INTO rResult | |
| * | |
| FROM dw.tabela1 | |
| -- COLOCAR FILTROS AQUI | |
| LOOP | |
| RETURN NEXT rResult; | |
| END LOOP; | |
| ELSE | |
| FOR rResult IN | |
| SELECT | |
| INTO rResult | |
| * | |
| FROM dw.tabela_dois | |
| -- COLOCAR FILTROS AQUI | |
| LOOP | |
| RETURN NEXT rResult; | |
| END LOOP; | |
| END IF; | |
| END; | |
| $$ LANGUAGE 'plpgsql'; | |
| -- Exemplo de chamada | |
| SELECT * FROM fnc_roda_selects() AS (col1 TEXT, col2 NUMERIC); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment