Created
February 19, 2016 10:22
-
-
Save adamantnz/8a4fe014b705323d3efd to your computer and use it in GitHub Desktop.
Redshift - Table rows by schema
This file contains hidden or 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
SELECT trim(pgdb.datname) AS DATABASE | |
,trim(pgn.nspname) AS SCHEMA | |
,trim(a.NAME) AS TABLE | |
,b.mbytes | |
,a.rows | |
FROM ( | |
SELECT db_id | |
,id | |
,NAME | |
,sum(rows) AS rows | |
FROM stv_tbl_perm a | |
GROUP BY db_id | |
,id | |
,NAME | |
) AS a | |
JOIN pg_class AS pgc ON pgc.oid = a.id | |
JOIN pg_namespace AS pgn ON pgn.oid = pgc.relnamespace | |
JOIN pg_database AS pgdb ON pgdb.oid = a.db_id | |
JOIN ( | |
SELECT tbl | |
,count(*) AS mbytes | |
FROM stv_blocklist | |
GROUP BY tbl | |
) b ON a.id = b.tbl | |
WHERE trim(pgn.nspname) = 'sat' | |
ORDER BY mbytes DESC | |
,a.db_id | |
,a.NAME; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment