Reputation: 143
How do I list a DB's tables with Python's DB API?
Failing that, is there another way to do it?
Thanks
Upvotes: 6
Views: 3025
Reputation: 318508
The DBAPI does not have a function for this so unfortunately you need to use SQL that is specific to the database engine (there is no standardized way to list tables).
SHOW TABLES
SELECT tablename FROM pg_tables WHERE schemaname = 'public'
SELECT name FROM sqlite_master WHERE type = 'table'
SELECT Distinct TABLE_NAME FROM information_schema.TABLES
SELECT table_name FROM all_tables
SELECT table_name FROM tables
Upvotes: 15