Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python DB API list tables

How do I list a DB's tables with Python's DB API?

Failing that, is there another way to do it?

Thanks

like image 712
user1458476 Avatar asked Jun 18 '12 08:06

user1458476


People also ask

How do I list all tables in DB?

All Database Tables If you want to list all tables in the Oracle database, you can query the dba_tables view. SELECT table_name FROM dba_tables ORDER BY table_name ASC; This view (and all others starting with dba_) are meant for database administrators.

How do I view tables in sqlite?

If you are running the sqlite3 command-line access program you can type ". tables" to get a list of all tables. Or you can type ". schema" to see the complete database schema including all tables and indices.


1 Answers

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

  • MySQL: SHOW TABLES
  • PostgreSQL: SELECT tablename FROM pg_tables WHERE schemaname = 'public'
  • SQLite: SELECT name FROM sqlite_master WHERE type = 'table'
  • MS SQL: SELECT Distinct TABLE_NAME FROM information_schema.TABLES
  • Oracle: SELECT table_name FROM all_tables
  • SAP HANA: SELECT table_name FROM tables
like image 73
ThiefMaster Avatar answered Oct 05 '22 23:10

ThiefMaster