Re: Get all table names that have a specific column

From: Doug Bloebaum <blabes(at)gmail(dot)com>
To: emilu(at)cs(dot)concordia(dot)ca
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Get all table names that have a specific column
Date: 2005-09-30 15:41:20
Message-ID: caa2de8a0509300841v73233b9fhfa85bab72ba3d0d@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 9/30/05, Emi Lu <emilu(at)cs(dot)concordia(dot)ca> wrote:
> Greetings,
>
> I am not very familiar with the system views/tables in postgreSQL. I'd
> like to get all table names that have a column let's say named "col1".

I'd use:

select table_name
from information_schema.columns
where table_schema='my_schema'
and column_name='col1'

Lots of good info here:
http://www.postgresql.org/docs/7.4/static/information-schema.html

On 9/30/05, Emi Lu <emilu(at)cs(dot)concordia(dot)ca> wrote:
>
> Greetings,
>
> I am not very familiar with the system views/tables in postgreSQL. I'd
> like to get all table names that have a column let's say named "col1".
>
> For example,
> t1 (... col1 varchar(3) ... )
> t2 (... col1 varchar(3) ... )
> t3 (... ...)
>
>
> After querying the system tables/views, I can get the result something
> like :
>
> tables contain column "col1"
> ---------------------------------------------
> t1
> t2
> (2 rows)
>
>
> Thanks a lot,
> Emi
>
>
>
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Martijn van Oosterhout 2005-09-30 15:41:44 Re: Help with inventory control
Previous Message Bricklen Anderson 2005-09-30 15:37:19 Re: Get all table names that have a specific column