Skip to content

Commit 9d4963e

Browse files
Merge pull request #8827 from artemyk/get_schema_fix_8697
BUG: sql_schema does not generate dialect-specific DDL
2 parents ac9b2ab + 0ddbb0c commit 9d4963e

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

doc/source/whatsnew/v0.15.2.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Bug Fixes
6565
- Bug in slicing a multi-index with an empty list and at least one boolean indexer (:issue:`8781`)
6666
- ``io.data.Options`` now raises ``RemoteDataError`` when no expiry dates are available from Yahoo (:issue:`8761`).
6767
- ``Timedelta`` kwargs may now be numpy ints and floats (:issue:`8757`).
68-
68+
- ``sql_schema`` now generates dialect appropriate ``CREATE TABLE`` statements (:issue:`8697`)
6969

7070

7171

pandas/io/sql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ def exists(self):
621621

622622
def sql_schema(self):
623623
from sqlalchemy.schema import CreateTable
624-
return str(CreateTable(self.table))
624+
return str(CreateTable(self.table).compile(self.pd_sql.engine))
625625

626626
def _execute_create(self):
627627
# Inserting table into database, add to MetaData object

pandas/io/tests/test_sql.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,19 @@ def test_to_sql_save_index(self):
11551155
def test_transactions(self):
11561156
self._transaction_test()
11571157

1158+
def test_get_schema_create_table(self):
1159+
self._load_test2_data()
1160+
tbl = 'test_get_schema_create_table'
1161+
create_sql = sql.get_schema(self.test_frame2, tbl, con=self.conn)
1162+
blank_test_df = self.test_frame2.iloc[:0]
1163+
1164+
self.drop_table(tbl)
1165+
self.conn.execute(create_sql)
1166+
returned_df = sql.read_sql_table(tbl, self.conn)
1167+
tm.assert_frame_equal(returned_df, blank_test_df)
1168+
self.drop_table(tbl)
1169+
1170+
11581171
class TestSQLiteAlchemy(_TestSQLAlchemy):
11591172
"""
11601173
Test the sqlalchemy backend against an in-memory sqlite database.

0 commit comments

Comments
 (0)