pandas.io.sql.has_table#
- pandas.io.sql.has_table(table_name, con, schema=None)[source]#
Check if a table exists in a SQL database.
Accepts the same connection types as
read_sql().- Parameters:
- table_namestr
Name of SQL table.
- conADBC Connection, SQLAlchemy connectable, str, or sqlite3 connection
ADBC provides high performance I/O with native type support, where available. Using SQLAlchemy makes it possible to use any DB supported by that library. If a DBAPI2 object, only sqlite3 is supported.
- schemastr, optional
Name of SQL schema in database to look in (if database flavor supports this). If None, use the default schema.
- Returns:
- bool
Whether the table exists.
See also
read_sql_tableRead SQL database table into a DataFrame.
DataFrame.to_sqlWrite records stored in a DataFrame to a SQL database.
Examples
>>> import sqlite3 >>> from pandas.io.sql import has_table >>> conn = sqlite3.connect(":memory:") >>> has_table("data", conn) False >>> pd.DataFrame({"a": [1, 2]}).to_sql("data", conn) 2 >>> has_table("data", conn) True >>> conn.close()