Re: newbie question... how do I get table structure?

From: Mark Gibson <gibsonm(at)cromwell(dot)co(dot)uk>
To: Aaron Bratcher <aaronbratcher(at)abdatatools(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: newbie question... how do I get table structure?
Date: 2004-02-06 14:42:51
Message-ID: 4023A7EB.7060202@cromwell.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Franco Bruno Borghesi 2004-02-06 15:00:46 Re: newbie question... how do I get table structure?
Previous Message Aaron Bratcher 2004-02-06 14:10:23 Re: newbie question... how do I get table structure?