Postgresql
Chema Cortes
pych3m4 en gmail.com
Mie Nov 22 03:02:13 CET 2006
El 2006/11/21, Alexis Roda <alexis.roda.villalonga en gmail.com> escribió:
> Una forma es consultando los catálogos de la base de datos:
>
> http://www.postgresql.org/docs/8.2/static/catalogs.html
> http://www.postgresql.org/docs/8.2/static/catalog-pg-attribute.html
Mejor sería usar el "information_schema", que es parte de la
definición ANSI SQL y, por lo tanto, más portable a las otras bases de
datos que cumplen con el estándar :
http://www.postgresql.org/docs/8.2/static/information-schema.html
from pprint import pprint
cur.execute("""SELECT table_name FROM information_schema.tables
WHERE table_schema='public' AND table_type='BASE TABLE'""")
tables=[x[0] for x in cur.fetchall()]
q="""SELECT column_name, data_type, numeric_scale, is_nullable
FROM information_schema.columns
WHERE table_name=%s
ORDER BY ordinal_position"""
for t in tables:
print t
print "="*len(t)
cur.execute(q,(t,))
pprint(cur.fetchall())
Más información sobre la lista de distribución Python-es