Re: System catalog and identifying

From: "Nigel J(dot) Andrews" <nandrews(at)investsystems(dot)co(dot)uk>
To: "(9902468)" <ville80(at)salo(dot)salonseutu(dot)fi>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: System catalog and identifying
Date: 2002-08-02 18:09:54
Message-ID: Pine.LNX.4.21.0208021906040.2710-100000@ponder.fairway2k.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 1 Aug 2002, (9902468) wrote:

> Hi all! Didn't find any info on this, so if I missed it please guide
> me to the info thx.
>
> I know the name of the table and now I need to know what columns this
> table has.
>
> First I search system catalog named pg_class inorder to get the
> postgre id of the table named relfilenode:
>
> select relfilenode from pg_class where relname = 'table_name';
>
> after that I search all column names from pg_attribute, like this:
>
> select attname from pg_attribute where attrelid = relfilenode;
>
> unfortunately, this returns correct names, but also some names that
> the system uses. How can I exclude these names?
>
> EXAMPLE:
> I get the following results:
>
> tableoid *
> cmax *
> xmax *
> cmin *
> xmin *
> oid *
> ctid *
> sarake_id
> nimi
> kuvaus
> tyyppi
> help
> taulu_id
>
> everything marked with * is unwanted.
>

SELECT a.attname
FROM pg_attribute a, pg_class c
WHERE c.oid = a.attrelid
AND c.relname = 'table_name'
AND a.attnum > 0
ORDER BY a.attnum

let's you do it from the table name in one query and gives you them in order.

--
Nigel J. Andrews
Director

---
Logictree Systems Limited
Computer Consultants

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Sullivan 2002-08-02 18:11:09 Re: [HACKERS] []performance issues
Previous Message Rod Taylor 2002-08-02 18:08:02 Re: [HACKERS] []performance issues