@@ -1373,6 +1373,48 @@ def insert_on_conflict(table, conn, keys, data_iter):
1373
1373
pandasSQL .drop_table ("test_insert_conflict" )
1374
1374
1375
1375
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
+
1376
1418
@pytest .mark .parametrize ("conn" , mysql_connectable )
1377
1419
def test_insertion_method_on_conflict_update (conn , request ):
1378
1420
# GH 14553: Example in to_sql docstring
0 commit comments