Thread: getting column names for tables..

getting column names for tables..

From
jerome
Date:
im using pgtclsh is there a possibility to get column names for tables?

TIA


Re: getting column names for tables..

From
Brett Schwarz
Date:
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