Thread: Listing the table fields ....

Listing the table fields ....

From
The Hermit Hacker
Date:

===================================================================
This message has been sent to a DEAD mailing list, and subsequently
reforwarded to the proper one: pgsql-sql@postgresql.org
===================================================================


Hi,

This piece of code list the the table fields with the attribute name and the
fieldtype.
How do I get the Field size for that attribute.
f code list the the table fields with the attribute name and the fieldtype.
How do I get the Field size for that attribute?
Eg, Say one of the attributes is :-

    name varchar (50)

    I want to trap the value 50.

I tried the typlen and typprtlen, but that was not what I was looking for.

# list table fields (attribute) in given table
def ListAllFields(pgcnx, table):
        list = []
        for node in pgcnx.query("""SELECT c.relname, a.attname, t.typname
                                                        FROM pg_class c,
pg_attribute a, pg_type t
                                                        WHERE c.relname = '%s'
AND
                                                                a.attnum > 0 AND
                                                                a.attrelid =
c.oid AND
                                                                a.atttypid =
t.oid
                                                        """ %
table).getresult():
                list.append(node[1], node[2], node[3])
        return list

Thanks,
Reshma.