Skip to content

Instantly share code, notes, and snippets.

@saihoooooooo
Created February 8, 2012 09:59
Show Gist options
  • Save saihoooooooo/1767578 to your computer and use it in GitHub Desktop.
Save saihoooooooo/1767578 to your computer and use it in GitHub Desktop.
Select the table with a column that contains 'user_id'
SELECT DISTINCT
class.relname
FROM
pg_attribute AS att
INNER JOIN pg_class AS class
ON class.oid = att.attrelid
WHERE
att.attnum > 0
AND att.attname = 'user_id'
AND class.relkind = 'r'
AND class.relname ! ~ * '.*ba?k.*'
ORDER BY
class.relname ASC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment