Skip to content

ENH: use text() for all sqlalchemy execution #42765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ env:
PANDAS_CI: 1
PATTERN: ((not slow and not network and not clipboard) or (single and db))
COVERAGE: true
SQLALCHEMY_WARN_20: true

jobs:
Linux_py38_IO:
Expand Down
16 changes: 14 additions & 2 deletions pandas/io/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ def execute(sql, con, params=None):
Results Iterable
"""
pandas_sql = pandasSQL_builder(con)
if isinstance(pandas_sql, SQLDatabase):
from sqlalchemy import text

sql = text(sql)
args = _convert_params(sql, params)
return pandas_sql.execute(*args)

Expand Down Expand Up @@ -1520,9 +1524,17 @@ def read_query(
read_sql

"""
args = _convert_params(sql, params)
if isinstance(sql, str):
if isinstance(params, (list, tuple)):
result = self.connectable.connect().exec_driver_sql(sql, tuple(params))
else:
from sqlalchemy import text

result = self.execute(*args)
sql = text(sql)
result = self.execute(sql, params)
else:
args = _convert_params(sql, params)
result = self.execute(*args)
columns = result.keys()

if chunksize is not None:
Expand Down