Re: is there a refactor

From: Peter Steinheuser <psteinheuser(at)myyearbook(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org, John Fabiani <johnf(at)jfcomputer(dot)com>
Subject: Re: is there a refactor
Date: 2011-04-05 14:49:54
Message-ID: BANLkTimqv-k0n7Fvq8Tg+6H3MWDrf3zBAw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

You could also do something like:

select nspname, relname, attname
from pg_attribute a
JOIN pg_class c ON (a.attrelid = c.oid)
JOIN pg_namespace n ON (n.oid = c.relnamespace)
where a.attname ~ 'yourcolumn'
and c.relname !~ 'pg'
and n.nspname not in ('pg_catalog','information_schema')
order by 1,2,3;

I'd functionalize it.

On Tue, Apr 5, 2011 at 10:44 AM, Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>wrote:

> On Tuesday, April 05, 2011 7:27:24 am John Fabiani wrote:
> > Hi,
> > I would like to have a simple way to retrieve information for a field
> name.
> > By that I mean have some SQL select that will return all the tables a
> field
> > name exist within a database. I did not find anything with google but of
> > course google depends on the search string.
> >
> > Thanks in advance,
> > Johnf
>
> test(5432)aklaver=>SELECT table_name from information_schema.columns where
> column_name = 'id';
> table_name
> ----------------
> user_test
> table2
> table1
> hours
> jedit_test
> topics
> t2
> stone
> serial_test
> messages
> binary_test
> user_test
> timestamp_test
> role_t
> py_test
> money_test
> lock_test
> local_1
> lang_test
> interval_test
> foob
> fooa
> fldlength
> fk_1
> default_test
> csv_null
> check_two
> check_test
> array_test
> (29 rows)
>
> --
> Adrian Klaver
> adrian(dot)klaver(at)gmail(dot)com
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>

--
Peter Steinheuser
psteinheuser(at)myyearbook(dot)com

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message John Fabiani 2011-04-05 14:58:48 Re: is there a refactor
Previous Message Adrian Klaver 2011-04-05 14:44:51 Re: is there a refactor