Re: getting column names for tables..

From: Brett Schwarz <brett_schwarz(at)yahoo(dot)com>
To: jerome <jerome(at)gmanmi(dot)tv>
Cc: PostgresGeneral <pgsql-general(at)postgresql(dot)org>
Subject: Re: getting column names for tables..
Date: 2002-09-10 01:06:11
Message-ID: 1031619971.1692.35.camel@thor
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
--
Brett Schwarz
brett_schwarz AT yahoo.com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message snpe 2002-09-10 01:07:46 Re: describe table query?
Previous Message Alex Krohn 2002-09-10 01:03:55 Re: describe table query?