On Mon, 2 Apr 2001 RbrtBrn3@aol.com wrote:
> Hi,
>
> I recently posted this same question a few weeks back but lost the reply
> someone kindly sent. The question again how exactly does this query work:
>
> it will return all attributes and respective data types of a given table':
>
> select attname, typname
> from pg_class c, pg_attribute a, pg_type t
> where relname = relation_name and
> attrelid = c.oid and
> atttypid = t.oid and
> attnum > 0
> order by attnum;
Understanding a few minutes' worth of the system tables hold will help a
lot here--you can find that in the Developer's Guide.
Eseentially, pg_class hold "classes" (ie tables, views, sequences,
etc.) pg_attribute holds "Attributes" (ie fields). This query joins
togetehr pg_class and pg_Attribute, showing you all attributes for a class
with name = 'relation name'. attnum > 0 is perhaps the only
odd part -- it has to do w/hiding certain system columns of tables that
ordinary users don't realize are there are don't care about.
--
Joel Burton <jburton@scw.org>
Director of Information Systems, Support Center of Washington