Created
October 4, 2022 09:36
-
-
Save rlindooren/766d6a0a80406cdda5edf706077d21cb to your computer and use it in GitHub Desktop.
Postgres find columns that don't have an index
This file contains 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
-- Looks at columns ending with '_id' (edit if needed in Where-clause) | |
select | |
col.table_name, | |
col.column_name, | |
idx.indexdef | |
from information_schema.columns col | |
left join pg_indexes idx | |
on col.table_name = idx.tablename | |
and idx.indexdef like '%' || col.column_name || '%' | |
where col.table_schema = 'public' | |
and col.column_name like '%_id' | |
and idx.indexdef is null | |
order by col.table_name, col.column_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment