How can one detect which tables are in a database?
Charles D Hixson <[email protected]>
| Newsgroups | gmane.comp.python.db.pysqlite.user |
|---|---|
| Message-ID | <[email protected]> |
In Postgresql I could do:
def listTables(conn):
""" given a database connection, list the tables included in that
database """
sql = \
"""select c.relname FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','') AND n.nspname NOT IN ('pg_catalog',
'pg_toast')
AND pg_catalog.pg_table_is_visible(c.oid);
"""
cur = conn.cursor()
cur.execute(sql)
tables = cur.fetchall()
return list( (tbl[0] for tbl in tables) )
but this is dependent upon various features of Postgresql. Still, it
shows the kind of function I'm after. Any suggestions? Any references?