@@ -1275,7 +1275,6 @@ def test_read_procedure(conn, request):
1275
1275
res2 = sql .read_sql ("CALL get_testdb();" , conn )
1276
1276
tm .assert_frame_equal (df , res2 )
1277
1277
1278
-
1279
1278
@pytest .mark .parametrize ("conn" , postgresql_connectable )
1280
1279
@pytest .mark .parametrize ("expected_count" , [2 , "Success!" ])
1281
1280
def test_copy_from_callable_insertion_method (conn , expected_count , request ):
@@ -1373,6 +1372,47 @@ def insert_on_conflict(table, conn, keys, data_iter):
1373
1372
pandasSQL .drop_table ("test_insert_conflict" )
1374
1373
1375
1374
1375
+ @pytest .mark .parametrize ("conn" , postgresql_connectable )
1376
+ def test_to_sql_on_public_schema_postgres (conn , request ):
1377
+ # GH 15988: Example in to_sql docstring
1378
+ conn = request .getfixturevalue (conn )
1379
+
1380
+ from sqlalchemy .engine import Engine
1381
+ from sqlalchemy .sql import text
1382
+
1383
+ create_sql = text (
1384
+ """
1385
+ CREATE TABLE test_public_schema (
1386
+ a integer PRIMARY KEY,
1387
+ b numeric,
1388
+ c text
1389
+ );
1390
+ """
1391
+ )
1392
+ if isinstance (conn , Engine ):
1393
+ with conn .connect () as con :
1394
+ with con .begin ():
1395
+ con .execute (create_sql )
1396
+ else :
1397
+ with conn .begin ():
1398
+ conn .execute (create_sql )
1399
+
1400
+ test_data = DataFrame ([[1 , 2.1 , "a" ], [2 , 3.1 , "b" ]], columns = list ("abc" ))
1401
+ test_data .to_sql (
1402
+ name = "test_public_schema" ,
1403
+ con = conn ,
1404
+ if_exists = "append" ,
1405
+ index = False ,
1406
+ schema = "public"
1407
+ )
1408
+
1409
+ df_out = sql .read_sql_table ("test_public_schema" , conn , schema = "public" )
1410
+ assert test_data .equals (df_out )
1411
+
1412
+ # Cleanup
1413
+ with sql .SQLDatabase (conn , need_transaction = True ) as pandasSQL :
1414
+ pandasSQL .drop_table ("test_public_schema" )
1415
+
1376
1416
@pytest .mark .parametrize ("conn" , mysql_connectable )
1377
1417
def test_insertion_method_on_conflict_update (conn , request ):
1378
1418
# GH 14553: Example in to_sql docstring
0 commit comments