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 | |
l_stmt text; | |
begin | |
select 'TRUNCATE ' || string_agg(format('%I.%I', schemaname, tablename), ',') | |
into l_stmt | |
from pg_tables | |
where schemaname in ('public', 'sources'); |
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
create or replace function | |
count_rows(schema text, tablename text) returns integer | |
as | |
$body$ | |
declare | |
result integer; | |
query varchar; | |
begin | |
query := 'SELECT reltuples::bigint AS estimate FROM pg_class WHERE oid = to_regclass(''' || schema || '.' || tablename || ''')'; | |
execute query into result; |