Re: Find all instances of a column in the entire database.

From: Chris Browne <cbbrowne(at)acm(dot)org>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Find all instances of a column in the entire database.
Date: 2008-05-16 16:21:08
Message-ID: 60d4nmfcej.fsf@dba2.int.libertyrms.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

gavinb(at)eclinic(dot)com(dot)au ("Gavin 'Beau' Baumanis") writes:
> I am hoping that you might be able to give me some assistance with the
> following task!
> I have a database with nearly 200 tables and I need to find all tables
> that contain a column of myColumnName.
>
> I was hoping there might be a built-in function for this task, but I
> have been unable to find any information through our good friend Mr.
> Google or by perusing the fine manual.
>
> Thanks in advance for any thoughts you might have.

I have a schema which has a number of attributes called "name_id":

metadata=# select n.nspname, r.relname from pg_class r, pg_namespace n, pg_attribute a where a.attname = 'name_id' and r.oid = attrelid and n.oid = relnamespace;
nspname | relname
----------+---------------------
registry | redacted
registry | redacted
registry | redacted
registry | redacted
registry | redacted
registry | redacted
registry | redacted
registry | redacted
registry | redacted
registry | redacted
registry | redacted
registry | redacted
registry | redacted
registry | redacted
registry | redacted
registry | redacted
registry | redacted
registry | redacted
registry | redacted
registry | redacted
registry | redacted
registry | redacted
registry | redacted
(23 rows)

Change 'name_id' to 'myColumnName' and you should get what you're
expecting...
--
"cbbrowne","@","acm.org"
http://cbbrowne.com/info/lsf.html
Signs of a Klingon Programmer - 17. "Klingon multitasking systems do
not support "time-sharing". When a Klingon program wants to run, it
challenges the scheduler in hand-to-hand combat and owns the machine."

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message sumaya 2008-05-17 22:58:40 dblinks
Previous Message Simon Riggs 2008-05-16 16:13:09 Re: Query tuning