Skip to content

Commit 9b7c3e5

Browse files
committed
57539: Fixed creation unnamed table when using public schema
Problem: - Table on public schema being lost when tried to be created Solution: - Used db_schema_name argument to specify schema name of adbc_ingest
1 parent e51039a commit 9b7c3e5

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

pandas/io/sql.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -2380,7 +2380,9 @@ def to_sql(
23802380
raise ValueError("datatypes not supported") from exc
23812381

23822382
with self.con.cursor() as cur:
2383-
total_inserted = cur.adbc_ingest(table_name, tbl, mode=mode)
2383+
total_inserted = cur.adbc_ingest(
2384+
table_name=name, data=tbl, mode=mode, db_schema_name=schema
2385+
)
23842386

23852387
self.con.commit()
23862388
return total_inserted

pandas/tests/io/test_sql.py

+42
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,48 @@ def insert_on_conflict(table, conn, keys, data_iter):
13731373
pandasSQL.drop_table("test_insert_conflict")
13741374

13751375

1376+
@pytest.mark.parametrize("conn", postgresql_connectable)
1377+
def test_to_sql_on_public_schema_postgres(conn, request):
1378+
# GH 15988: Example in to_sql docstring
1379+
conn = request.getfixturevalue(conn)
1380+
1381+
from sqlalchemy.engine import Engine
1382+
from sqlalchemy.sql import text
1383+
1384+
create_sql = text(
1385+
"""
1386+
CREATE TABLE test_public_schema (
1387+
a integer PRIMARY KEY,
1388+
b numeric,
1389+
c text
1390+
);
1391+
"""
1392+
)
1393+
if isinstance(conn, Engine):
1394+
with conn.connect() as con:
1395+
with con.begin():
1396+
con.execute(create_sql)
1397+
else:
1398+
with conn.begin():
1399+
conn.execute(create_sql)
1400+
1401+
test_data = DataFrame([[1, 2.1, "a"], [2, 3.1, "b"]], columns=list("abc"))
1402+
test_data.to_sql(
1403+
name="test_public_schema",
1404+
con=conn,
1405+
if_exists="append",
1406+
index=False,
1407+
schema="public",
1408+
)
1409+
1410+
df_out = sql.read_sql_table("test_public_schema", conn, schema="public")
1411+
assert test_data.equals(df_out)
1412+
1413+
# Cleanup
1414+
with sql.SQLDatabase(conn, need_transaction=True) as pandasSQL:
1415+
pandasSQL.drop_table("test_public_schema")
1416+
1417+
13761418
@pytest.mark.parametrize("conn", mysql_connectable)
13771419
def test_insertion_method_on_conflict_update(conn, request):
13781420
# GH 14553: Example in to_sql docstring

0 commit comments

Comments
 (0)