Re: describe table query?

Alex Krohn <alex@gossamer-threads.com>

From: Alex Krohn <alex@gossamer-threads.com>
To: Andrew Bulmer <toastafari@yahoo.com>
Cc: pgsql-general@postgresql.org
Date: 2002-09-10T01:03:55Z
Lists: 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>