Skip to content

Instantly share code, notes, and snippets.

View jitscar's full-sized avatar

jitscar

View GitHub Profile
@jitscar
jitscar / clean_data_postgre.sql
Last active March 7, 2019 11:57
Clean all data in PostreSql db
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');
@jitscar
jitscar / tables_count_postgre.sql
Last active March 5, 2019 15:31
Fast count of table rows in PostgreSql
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;