From: | GreyGeek <jkreps(at)neb(dot)rr(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: list fieldnames in table? (from PHP) |
Date: | 2004-10-27 04:02:20 |
Message-ID: | g5Ffd.12092$T02.2334@twister.rdc-kc.rr.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Miles Keaton wrote:
> Is there a simple way to list fieldnames in a table, from PHP?
>
> When on the command-line, I just do \d tablename
>
> But how to get the fieldnames from PHP commands?
>
> ---------------------------(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
Here is one way Python can do it through ODBC:
# fetch descriptions to create field name dictionaries
try:
ci = db.cursor()
ci.execute("select * from PERSINFO where 1 = 0")
column = 0
for d in ci.description: # key : value
PersFields[d[0]] = column # field name : position
PersPos[column] = d[0] # position : field name d[0]
PersTypes[d[0]] = d[1] # field name : data type d[1]
PersPrec[d[0]] = d[4] # field name : precision d[4]
PersScale[d[0]] = d[5] # field name : scale d[5]
PersVals[column] = None # position : value (init=None)
column += 1
ci.close()
ci = None
--
--
GreyGeek
From | Date | Subject | |
---|---|---|---|
Next Message | Robby Russell | 2004-10-27 04:08:44 | Re: primary key and existing unique fields |
Previous Message | mayra | 2004-10-27 03:12:35 | Theory |