Skip to content

Instantly share code, notes, and snippets.

I may be slow to respond.

Oguzhan oguzhan

I may be slow to respond.
View GitHub Profile
View redshift-utils.sql
-- sort by row count
select trim(pgdb.datname) as Database, trim(pgns.nspname) as Schema, trim( as Table,
c.rows, ((b.mbytes/*100)::decimal(5,3) as pct_of_total, b.mbytes, b.unsorted_mbytes
from stv_tbl_perm a
join pg_class as pgtbl on pgtbl.oid =
join pg_namespace as pgns on pgns.oid = pgtbl.relnamespace
join pg_database as pgdb on pgdb.oid = a.db_id
join (select tbl, sum(decode(unsorted, 1, 1, 0)) as unsorted_mbytes, count(*) as mbytes from stv_blocklist group by tbl) b on
join (select id, sum(rows) as rows from stv_tbl_perm group by id) c on
join (select sum(capacity) as total from stv_partitions where part_begin=0) as part on 1=1