Re: describe table query?

From: Alex Krohn <alex(at)gossamer-threads(dot)com>
To: Andrew Bulmer <toastafari(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: describe table query?
Date: 2002-09-10 01:03:55
Message-ID: 20020909180030.DC3B.ALEX@gossamer-threads.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
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(at)gossamer-threads(dot)com>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Brett Schwarz 2002-09-10 01:06:11 Re: getting column names for tables..
Previous Message snpe 2002-09-10 00:43:22 Column type, size, precision in PostgreSQL