Last active
June 29, 2022 17:43
-
-
Save deeTEEcee/96600b75776a0ac7f2d4086ddb1d1fea to your computer and use it in GitHub Desktop.
postgres developer snippets
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
-- Get Postgres Summary | |
-- | |
create or replace function | |
count_rows(schema text, tablename text) returns integer | |
as | |
$body$ | |
declare | |
result integer; | |
query varchar; | |
begin | |
query := 'SELECT count(1) FROM ' || schema || '.' || tablename; | |
execute query into result; | |
return result; | |
end; | |
$body$ | |
language plpgsql; | |
select table_name, pg_relation_size('<schema_id>' || '.' || table_name), count_rows(quote_ident('<schema_id>'), table_name) | |
from information_schema.tables | |
where table_schema = '<schema_id>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment