Skip to content

BUG: sql_schema does not generate dialect-specific DDL #8827

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

Merged
merged 1 commit into from
Nov 17, 2014
Merged
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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.15.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Bug Fixes
- Bug in slicing a multi-index with an empty list and at least one boolean indexer (:issue:`8781`)
- ``io.data.Options`` now raises ``RemoteDataError`` when no expiry dates are available from Yahoo (:issue:`8761`).
- ``Timedelta`` kwargs may now be numpy ints and floats (:issue:`8757`).

- ``sql_schema`` now generates dialect appropriate ``CREATE TABLE`` statements (:issue:`8697`)



Expand Down
2 changes: 1 addition & 1 deletion pandas/io/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ def exists(self):

def sql_schema(self):
from sqlalchemy.schema import CreateTable
return str(CreateTable(self.table))
return str(CreateTable(self.table).compile(self.pd_sql.engine))

def _execute_create(self):
# Inserting table into database, add to MetaData object
Expand Down
13 changes: 13 additions & 0 deletions pandas/io/tests/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,19 @@ def test_to_sql_save_index(self):
def test_transactions(self):
self._transaction_test()

def test_get_schema_create_table(self):
self._load_test2_data()
tbl = 'test_get_schema_create_table'
create_sql = sql.get_schema(self.test_frame2, tbl, con=self.conn)
blank_test_df = self.test_frame2.iloc[:0]

self.drop_table(tbl)
self.conn.execute(create_sql)
returned_df = sql.read_sql_table(tbl, self.conn)
tm.assert_frame_equal(returned_df, blank_test_df)
self.drop_table(tbl)


class TestSQLiteAlchemy(_TestSQLAlchemy):
"""
Test the sqlalchemy backend against an in-memory sqlite database.
Expand Down