pandas.read_sql_query
pandas 3.1.1 · Input and output · function
Execute a SELECT query and load its result. Supply query values through params.
Call syntax
pd.read_sql_query(…) Full signature
pd.read_sql_query(
sql,
con,
index_col=None,
coerce_float=True,
params=None,
parse_dates=None,
chunksize=None,
dtype=None,
dtype_backend=…,
)Run the example
Edit the example and select Run Python to see the result.
Parameters
| Parameter | Requirement | Accepted values and behavior |
|---|---|---|
sql |
Required Positional or keyword |
str SQL query or SQLAlchemy Selectable (select or text object) |
con |
Required Positional or keyword |
SQLAlchemy connectable, str, or sqlite3 connection Provide a database connection or supported SQLAlchemy connectable. |
index_col |
Optional Positional or keyword Default None |
str or list of str Identify the column or columns whose values should become the row index. |
coerce_float |
Optional Positional or keyword Default True |
bool Attempt to convert compatible nonfloating values to floating-point values. |
params |
Optional Positional or keyword Default None |
list, tuple or mapping Supply the values bound to SQL query placeholders. |
parse_dates |
Optional Positional or keyword Default None |
list or dict Choose whether to interpret selected fields as dates during a read. |
chunksize |
Optional Positional or keyword Default None |
int Set how many rows to read or write in each batch. |
dtype |
Optional Positional or keyword Default None |
Type name or dict of columns Choose the data type for the input conversion or result. |
dtype_backend |
Optional Positional or keyword |
{'numpy_nullable', 'pyarrow'} Choose nullable NumPy-backed dtypes or Arrow-backed dtypes. |
Returns
DataFrame or Iterator[DataFrame]