pandas.read_sql

pandas 3.1.1 · Input and output · function

Load a database table or SQL query result as a DataFrame.

Call syntax

pd.read_sql(…) Full signature
pd.read_sql(
    sql,
    con,
    index_col=None,
    coerce_float=True,
    params=None,
    parse_dates=None,
    columns=None,
    chunksize=None,
    dtype_backend=…,
    dtype=None,
)

Run the example

Edit the example and select Run Python to see the result.

Parameters

ParameterRequirementAccepted values and behavior
sql Required
Positional or keyword
str or SQLAlchemy Selectable (select or text object)
con Required
Positional or keyword
ADBC Connection, 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 dict

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.

columns Optional
Positional or keyword
Default None
list

Supply column labels or control how columns are handled.

chunksize Optional
Positional or keyword
Default None
int

Set how many rows to read or write in each batch.

dtype_backend Optional
Positional or keyword
{'numpy_nullable', 'pyarrow'}

Choose nullable NumPy-backed dtypes or Arrow-backed dtypes.

dtype Optional
Positional or keyword
Default None
Type name or dict of columns

Choose the data type for the input conversion or result.

Returns

DataFrame or Iterator[DataFrame]