Re: list all columns in db - Mailing list pgsql-general

From Jon Sime
Subject Re: list all columns in db
Date
Msg-id 46688857.30003@mediamatters.org
Whole thread Raw
In response to list all columns in db  (Jonathan Vanasco <postgres@2xlp.com>)
Responses Re: list all columns in db
Re: list all columns in db
Re: list all columns in db
List pgsql-general
Jonathan Vanasco wrote:
>
> Does anyone have a trick to list all columns in a db ?

No trickery, just exploit the availability of the SQL standard
information_schema views:

     select table_schema, table_name, column_name
     from information_schema.columns
     where table_schema not in ('pg_catalog','information_schema')
     order by 1,2,3

If you want an equivalent that uses pg_catalog (non-portable outside of
PostgreSQL) you could instead do:

     select n.nspname as table_schema, c.relname as table_name,
         a.attname as column_name
     from pg_catalog.pg_attribute a
         join pg_catalog.pg_class c on (a.attrelid = c.oid)
         join pg_catalog.pg_namespace n on (c.relnamespace = n.oid)
     where c.relkind in ('r','v') and a.attnum > 0
         and n.nspname not in ('pg_catalog','information_schema')
     order by 1,2,3

-Jon

--
Senior Systems Developer
Media Matters for America
http://mediamatters.org/

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: index vs. seq scan choice?
Next
From: "George Pavlov"
Date:
Subject: Re: index vs. seq scan choice?