Is there any way to get a list of all tables available through an odbc connection.
I have to fetch data from tables that are generated along the way, and therefore I don't know the names in advance.
(the ODBC driver was not specifie at time of this answer)
From PyODBC documentation:
Most of the ODBC catalog functions are available as methods on Cursor objects. The results are presented as SELECT results in rows that are fetched normally. The Cursor page documents these, but it may be helpful to refer to Microsoft's ODBC documentation for more details.
cnxn = pyodbc.connect(...)
cursor = cnxn.cursor()
for row in cursor.tables():
print row.table_name
EDIT: as OP specified using "Anaconda ODBC":
As far as I know, there is no direct access to those data from PyWin32-odbc (as I think this is what Anacondas uses). Depending your underlying DB they might be a "system table" that you might query. Something like sys.objects
or dbo.sysobjects
or information_schema.tables
or ... (RDBMS vendors are very creative in that area).
Please see the doc of the underlying RDBMS for more info. Or (as of myself, I would strongly push toward that), file a request to install a more versatile ODBC driver...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With