2

I am trying to clean up a Postgres database and create some consistency in the naming conventions.

I would like generate a list of the functions where the columns exist as a checklist to work from.

I was wondering if there was an easier way than dumping the function definitions to a file and searching each column individually?

1 Answer 1

3

To find tables and views containing ColumnName:

SELECT attrelid::regclass
FROM pg_attribute
WHERE attname = 'columnname'

To find functions which mention ColumnName somewhere in their code:

SELECT oid::regprocedure, prosrc
FROM pg_proc
WHERE prosrc ~* '\yColumnName\y'

(~* is a case-insensitive regex match, \y represents a word boundary.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.