Re: describe table query? - Mailing list pgsql-general

From Alex Krohn
Subject Re: describe table query?
Date
Msg-id 20020909180030.DC3B.ALEX@gossamer-threads.com
Whole thread Raw
In response to describe table query?  (Andrew Bulmer <toastafari@yahoo.com>)
List pgsql-general
Hi Andrew,

> I'm trying to write an Access clone in java that will
> use PostGres as a backend. Problem is, I need to be
> able to list all the fields (and data types) in a
> table. I know about "\d" but that only seems to work
> on the command line client (doesn't work if I pass it
> in as a query). I know in mysql DESCRIBE <table> will
> do it... is there an equivalent in postgres? I tried
> google but all I could find were references to the \d command.

We use:

SELECT a.attnum, a.attname, t.typname, a.attlen, a.atttypmod, a.attnotnull, a.atthasdef
FROM pg_class c, pg_attribute a, pg_type t
WHERE c.relname = 'YOURTABLE'
    and a.attnum > 0
    and a.attrelid = c.oid
    and a.atttypid = t.oid
ORDER BY attnum

But I'd be interested to hear if there is a better way. =)

Hope that helps,

Alex

--
Alex Krohn <alex@gossamer-threads.com>

pgsql-general by date:

Previous
From: Dan Ostrowski
Date:
Subject: Re: describe table query?
Next
From: Bruce Momjian
Date:
Subject: Re: AutoCommit mode in PostgreSQL (7.3 beta1 from CVS 05.09.2002)