Skip to content

Instantly share code, notes, and snippets.

@stefanthoss
Created October 9, 2019 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanthoss/d0125ac9687f9736b6bcb4e3eedee027 to your computer and use it in GitHub Desktop.
Save stefanthoss/d0125ac9687f9736b6bcb4e3eedee027 to your computer and use it in GitHub Desktop.
Find PostgreSQL tables that have columns which match a certain regex.
SELECT
t.table_schema,
t.table_name,
c.column_name
FROM
information_schema.tables t
INNER JOIN information_schema.columns c ON c.table_name = t.table_name
AND c.table_schema = t.table_schema
WHERE
c.column_name ~ 'regex'
AND t.table_type = 'BASE TABLE'
ORDER BY
t.table_schema ASC,
t.table_name ASC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment