Created
November 19, 2016 14:52
-
-
Save dexalex84/0d68e31050a4cfae5776b615ed954c2f to your computer and use it in GitHub Desktop.
PostgreSQL Count of rows in tables in one schema by simple count and store in temp table
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
; | |
do | |
$$ | |
DECLARE var_table_name character varying(1000); | |
var_cnt bigint; | |
begin | |
drop table if exists temp_tables;-- ( character varying(1000), bigint); | |
create temp table if not exists temp_tables (table_name character varying(1000), cnt bigint); | |
truncate table tt_tables; | |
for var_table_name in select table_name from information_schema.tables tt where tt.table_schema = 'tempdownload' loop | |
insert into temp_tables(table_name) | |
select var_table_name; | |
end loop; | |
for var_table_name in select table_name from temp_tables loop | |
execute 'select count(*) from tempdownload."'||var_table_name||'";' | |
into var_cnt; | |
raise notice 'processing table tempdownload."%"',var_table_name; | |
update temp_tables | |
set cnt = var_cnt | |
where | |
temp_tables.table_name = var_table_name; | |
end loop; | |
end; | |
$$ | |
language 'plpgsql'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment