From: | Joel Burton <jburton(at)scw(dot)org> |
---|---|
To: | RbrtBrn3(at)aol(dot)com |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Can anyone explain how this works? |
Date: | 2001-04-08 09:50:26 |
Message-ID: | Pine.LNX.4.21.0104080548130.19671-100000@olympus.scw.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Mon, 2 Apr 2001 RbrtBrn3(at)aol(dot)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(at)scw(dot)org>
Director of Information Systems, Support Center of Washington
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Eisentraut | 2001-04-08 10:05:42 | Re: Casting numeric to text |
Previous Message | Louis-David Mitterrand | 2001-04-08 09:36:38 | Re: Maybe a Bug, maybe bad SQL |