Created
July 31, 2020 13:32
-
-
Save RaulMedeiros/5399a4aa005883494828db9410a02162 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
CREATE OR REPLACE FUNCTION qtd(nomeTabela text) RETURNS integer LANGUAGE plpgsql AS $$ | |
DECLARE | |
resultado integer; | |
BEGIN | |
EXECUTE 'SELECT count(1) FROM ' || nomeTabela INTO resultado; | |
RETURN resultado; | |
END; $$; | |
Uso da função: | |
SELECT qtd('tabela_estoque'); | |
SELECT qtd('tabela_produtos'); | |
Outro uso exemplo: | |
CREATE OR REPLACE FUNCTION dropConstraint(nomeTabela text, nomeConstraint text) RETURNS void LANGUAGE plpgsql AS $$ | |
BEGIN | |
EXECUTE 'ALTER TABLE ' || nomeTabela || ' DROP CONSTRAINT ' || nomeConstraint; | |
END; $$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment