Last active
December 15, 2020 20:11
-
-
Save byk0t/704c545f2c3264be52fa0b7d7e004ced to your computer and use it in GitHub Desktop.
PostgreSQL, Get comma separated list of tables based on a table name.
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 table by name | |
SELECT string_agg(table_name, ', ') | |
FROM information_schema.tables | |
WHERE table_schema='public' | |
AND table_type='BASE TABLE' | |
AND table_name like 't_%' | |
-- select only empty tables | |
select | |
string_agg(relname, ', ') | |
from pg_catalog.pg_statio_user_tables | |
where relname like 't_%' and pg_size_pretty(pg_relation_size(relid)) = '0 bytes' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment