Skip to content

Instantly share code, notes, and snippets.

@deeTEEcee
Last active June 29, 2022 17:43
Show Gist options
  • Save deeTEEcee/96600b75776a0ac7f2d4086ddb1d1fea to your computer and use it in GitHub Desktop.
Save deeTEEcee/96600b75776a0ac7f2d4086ddb1d1fea to your computer and use it in GitHub Desktop.
postgres developer snippets
-- 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