Skip to content

Instantly share code, notes, and snippets.

@byk0t
Last active December 15, 2020 20:11
Show Gist options
  • Save byk0t/704c545f2c3264be52fa0b7d7e004ced to your computer and use it in GitHub Desktop.
Save byk0t/704c545f2c3264be52fa0b7d7e004ced to your computer and use it in GitHub Desktop.
PostgreSQL, Get comma separated list of tables based on a table name.
-- 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