Re: newbie question... how do I get table structure? - Mailing list pgsql-general

From Mark Gibson
Subject Re: newbie question... how do I get table structure?
Date
Msg-id 4023A7EB.7060202@cromwell.co.uk
Whole thread Raw
In response to Re: newbie question... how do I get table structure?  (Aaron Bratcher <aaronbratcher@abdatatools.com>)
List pgsql-general
Aaron Bratcher wrote:

> Is there no way I can do it with a standard select command in a
> different client? I don't need the indexes, just the column names/types.
>

For PostgreSQL 7.3 and above:

SELECT
    a.attname,
    format_type(a.atttypid, a.atttypmod)
FROM
    pg_catalog.pg_class c INNER JOIN
    pg_catalog.pg_namespace n ON (c.relnamespace = n.oid) INNER JOIN
    pg_catalog.pg_attribute a ON (a.attrelid = c.oid)
WHERE
    n.nspname = '{schema_name}' AND
    c.relname = '{table_name}' AND
    a.attisdropped = false AND
    a.attnum > 0

Replace {schema_name} and {table_name}.

--
Mark Gibson <gibsonm |AT| cromwell |DOT| co |DOT| uk>
Web Developer & Database Admin
Cromwell Tools Ltd.
Leicester, England.


pgsql-general by date:

Previous
From: Aaron Bratcher
Date:
Subject: Re: newbie question... how do I get table structure?
Next
From: "Henrik Steffen"
Date:
Subject: Re: newbie question... how do I get table structure?