Re: list fieldnames in table? (from PHP) - Mailing list pgsql-general

From GreyGeek
Subject Re: list fieldnames in table? (from PHP)
Date
Msg-id g5Ffd.12092$T02.2334@twister.rdc-kc.rr.com
Whole thread Raw
In response to list fieldnames in table? (from PHP)  (Miles Keaton <mileskeaton@gmail.com>)
List 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@postgresql.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

pgsql-general by date:

Previous
From: Kevin Barnard
Date:
Subject: Re: Superuser log-in through a web interface?
Next
From: Thomas Hallgren
Date:
Subject: Re: Bug or stupidity