From: Tom Lane <tgl@sss.pgh.pa.us>
To: dbmss@yahoo.com
Cc: pgsql-sql@hub.org
Subject: Re: Question about schema
Date: Wed, 25 Nov 1998 10:55:33 -0500
Message-ID: <28219.912009333@sss.pgh.pa.us> (raw)
In-Reply-To: <199811250400.XAA10150@hub.org>
dbmss@yahoo.com writes:
> Can I use SQL to get info about a table
> which can be gotten by doing a
> \d [table name]
> under psql?
psql uses plain old SQL queries to extract the info it presents with \d;
it's not doing anything you couldn't do too. Read the source code for
psql (src/bin/psql/psql.c) to see what queries are used to produce the
various sorts of \d reports. For example, the particular case of
"\d table" is handled in the routine named tableDesc, and from looking
at that you can see that it constructs a primary query like this:
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 = '<table name here>'
and a.attnum > 0
and a.attrelid = c.oid
and a.atttypid = t.oid
ORDER BY attnum
Looks like there are additional queries made to get the values of field
defaults and so forth.
All this stuff is kept in the system tables, and you can query those
tables with ordinary queries.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, dbmss@yahoo.com, pgsql-sql@hub.org
Subject: Re: Question about schema
In-Reply-To: <28219.912009333@sss.pgh.pa.us>
References: <199811250400.XAA10150@hub.org> <28219.912009333@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox