Re: getting column names for tables.. - Mailing list pgsql-general

From Brett Schwarz
Subject Re: getting column names for tables..
Date
Msg-id 1031619971.1692.35.camel@thor
Whole thread Raw
In response to getting column names for tables..  (jerome <jerome@gmanmi.tv>)
List pgsql-general
set conn [pg_connect -conninfo "..."]
set res [pg_exec $conn "SELECT * FROM some_table"]
set attList [pg_result $res -attributes]

    .
    .
    .
pg_result $res -clear

Note that your select statement will determine *which* columns are
returned. The above is good if you want the actual tuples returned as
well. But if all you want are the attributes, then you could add a
"LIMIT 1" to the end of the SQL, or you could use this sql, and retrieve
the tuples (which will be the columns):

  SELECT A.attname
    FROM Pg_class C, Pg_attribute A
   WHERE C.oid = A.attrelid

I *think* that's it...I am doing it from memory. You may have to tweak
it...and I think 7.3 will be different if I recall...

HTH,

    --brett


On Tue, 2002-09-10 at 06:27, jerome wrote:
> im using pgtclsh is there a possibility to get column names for tables?
>
> TIA
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
--
Brett Schwarz
brett_schwarz AT yahoo.com


pgsql-general by date:

Previous
From: "oclam"
Date:
Subject: Compare chinese words
Next
From: Josh Jore
Date:
Subject: Psql regex is NFA or DFA?