Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 7EABA1337BF2 for ; Tue, 5 Apr 2011 11:57:00 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 03401-03 for ; Tue, 5 Apr 2011 14:56:53 +0000 (UTC) X-Greylist: delayed 00:06:38.79482 by SQLgrey-1.7.6 Received: from mail-vw0-f46.google.com (mail-vw0-f46.google.com [209.85.212.46]) by mail.postgresql.org (Postfix) with ESMTP id 0D6611337BF8 for ; Tue, 5 Apr 2011 11:56:52 -0300 (ADT) Received: by vws1 with SMTP id 1so318258vws.19 for ; Tue, 05 Apr 2011 07:56:53 -0700 (PDT) Received: by 10.52.18.14 with SMTP id s14mr2985304vdd.164.1302015014213; Tue, 05 Apr 2011 07:50:14 -0700 (PDT) MIME-Version: 1.0 Received: by 10.52.157.65 with HTTP; Tue, 5 Apr 2011 07:49:54 -0700 (PDT) In-Reply-To: <201104050744.52471.adrian.klaver@gmail.com> References: <201104050727.24713.johnf@jfcomputer.com> <201104050744.52471.adrian.klaver@gmail.com> From: Peter Steinheuser Date: Tue, 5 Apr 2011 10:49:54 -0400 Message-ID: Subject: Re: is there a refactor To: Adrian Klaver Cc: pgsql-sql@postgresql.org, John Fabiani Content-Type: multipart/alternative; boundary=20cf3054a12f6a17a304a02cfe4c X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.899 tagged_above=-5 required=5 tests=BAYES_00=-1.9, HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 201104/4 X-Sequence-Number: 35251 --20cf3054a12f6a17a304a02cfe4c Content-Type: text/plain; charset=ISO-8859-1 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 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.klaver@gmail.com > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql > -- Peter Steinheuser psteinheuser@myyearbook.com --20cf3054a12f6a17a304a02cfe4c Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable You could also do something like:

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

I'd functional= ize it.

On Tue, Apr 5, 2011 at 10:44 AM, = Adrian Klaver <adrian.klaver@gmail.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. =A0I did not find anything with google b= ut of
> course google depends on the search string.
>
> Thanks in advance,
> Johnf

test(5432)aklaver=3D>SELECT table_name from information_schema.columns = =A0where
column_name =3D 'id';
=A0 table_name
----------------
=A0user_test
=A0table2
=A0table1
=A0hours
=A0jedit_test
=A0topics
=A0t2
=A0stone
=A0serial_test
=A0messages
=A0binary_test
=A0user_test
=A0timestamp_test
=A0role_t
=A0py_test
=A0money_test
=A0lock_test
=A0local_1
=A0lang_test
=A0interval_test
=A0foob
=A0fooa
=A0fldlength
=A0fk_1
=A0default_test
=A0csv_null
=A0check_two
=A0check_test
=A0array_test
(29 rows)

--
Adrian Klaver
adrian.klaver@gmail.com

--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
= http://www.postgresql.org/mailpref/pgsql-sql



--
Peter Steinheuse= r
psteinheuser@myyearbook= .com
--20cf3054a12f6a17a304a02cfe4c--