Re: describe table query?
От
scott.marlowe
Тема
Re: describe table query?
Дата
Msg-id
Pine.LNX.4.33.0209100955300.4854-100000@css120.ihs.com
Ответ на
Re: describe table query? (Dan Ostrowski)
Список
Дерево обсуждения
describe table query? Andrew Bulmer <toastafari@yahoo.com>
Re: describe table query? Alex Krohn <alex@gossamer-threads.com>
Re: describe table query? snpe <snpe@snpe.co.yu>
Re: describe table query? Dan Ostrowski <dan@triad-dev.com>
Re: describe table query? snpe <snpe@snpe.co.yu>
Re: describe table query? "scott.marlowe" <scott.marlowe@ihs.com>
Re: describe table query? snpe <snpe@snpe.co.yu>
Re: describe table query? "scott.marlowe" <scott.marlowe@ihs.com>
Re: describe table query? snpe <snpe@snpe.co.yu>
Re: describe table query? Andrew Bulmer <toastafari@yahoo.com>
Re: describe table query? Darren Ferguson <darren@crystalballinc.com>
There are two ways to do this. One is the postgresql specific way, which is to crank up psql with the -E switch, then issue a \d for a table, and copy out the sql query that goes by. On my 7.2.1 box, that gives me a set of queries like so for a table named 'bubba': smarlowe=# \d bubba ********* QUERY ********** SELECT relhasindex, relkind, relchecks, reltriggers, relhasrules FROM pg_class WHERE relname='bubba' ************************** This NEXT one describes the table for us: ********* QUERY ********** SELECT a.attname, format_type(a.atttypid, a.atttypmod), a.attnotnull, a.atthasdef, a.attnum FROM pg_class c, pg_attribute a WHERE c.relname = 'bubba' AND a.attnum > 0 AND a.attrelid = c.oid ORDER BY a.attnum ************************** This one tells us what indexes it has: ********* QUERY ********** SELECT c2.relname FROM pg_class c, pg_class c2, pg_index i WHERE c.relname = 'bubba' AND c.oid = i.indrelid AND i.indexrelid = c2.oid AND NOT i.indisunique ORDER BY c2.relname ************************** I'm not sure what the next two do, I think they have to do with foreign keys. ********* QUERY ********** SELECT c2.relname FROM pg_class c, pg_class c2, pg_index i WHERE c.relname = 'bubba' AND c.oid = i.indrelid AND i.indexrelid = c2.oid AND i.indisprimary AND i.indisunique ORDER BY c2.relname ************************** ********* QUERY ********** SELECT c2.relname FROM pg_class c, pg_class c2, pg_index i WHERE c.relname = 'bubba' AND c.oid = i.indrelid AND i.indexrelid = c2.oid AND NOT i.indisprimary AND i.indisunique ORDER BY c2.relname ************************** This one gives us our constraints: ********* QUERY ********** SELECT rcsrc, rcname FROM pg_relcheck r, pg_class c WHERE c.relname='bubba' AND c.oid = r.rcrelid ************************** The other way to do it is to issue a single query of the form "Select * from table limit 1" and use pg_num_fields, pg_field_name and pg_field_type commands to walk the returned fields to find their name and type. The advantage of this method is that it is somewhat more transportable to other dbmses. On Mon, 9 Sep 2002, Dan Ostrowski wrote: > I also would love to know how you do this, because I am REALLY missing the "DESCRIBE
В списке pgsql-general по дате отправления