Listing the table fields .... - Mailing list pgsql-sql

From The Hermit Hacker
Subject Listing the table fields ....
Date
Msg-id Pine.BSF.3.96.980515002720.438W-100000@thelab.hub.org
Whole thread Raw
List pgsql-sql

===================================================================
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.


pgsql-sql by date:

Previous
From: "Jose' Soares Da Silva"
Date:
Subject: Re: Referential Integrity
Next
From: "Igor Sysoev"
Date:
Subject: Re: [SQL] Perl and SQL