Skip to content

datetime64 columns not supported with sqlite fallback #7567

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

Closed
jorisvandenbossche opened this issue Jun 25, 2014 · 2 comments · Fixed by #8208
Closed

datetime64 columns not supported with sqlite fallback #7567

jorisvandenbossche opened this issue Jun 25, 2014 · 2 comments · Fixed by #8208
Labels
IO SQL to_sql, read_sql, read_sql_query
Milestone

Comments

@jorisvandenbossche
Copy link
Member

From http://stackoverflow.com/questions/24389580/pandas-to-sql-method-gives-error-with-date-column

import sqlite3
con = sqlite3.connect(':memory:')
df = pd.DataFrame({'date':pd.date_range('2014-01-01', periods=10)})
df.to_sql('test_datetime', con, index=False, if_exists='append')

gives an InterfaceError: Error binding parameter 0 - probably unsupported type.. While it does work if you have datetime.datetime/date objects (instead of datetime64):

df2 = df.copy()
df2['date'] = pd.DatetimeIndex(df2['date']).date
df2.to_sql('test_datetime', con, index=False, if_exists='append')

and it does also work with a sqlalchemy engine (sqlalchemy converts it to a string):

import sqlalchemy
engine = sqlalchemy.create_engine('sqlite:///memory')
df.to_sql('test_datetime', engine, index=False, if_exists='append')

I think this should also work in the fallback mode, options are to convert it to datetime.datetime objects and let sqlite3 do the work to convert it to a string, or to convert it to a string directly ourselves.

@jreback jreback added this to the 0.15.0 milestone Jul 7, 2014
@jorisvandenbossche
Copy link
Member Author

Or another option would maybe to register an adapter/converter for Timestamp with sqlite3.register_adapter.

Further, other date/time related issues with SQLite fallback:

@jorisvandenbossche
Copy link
Member Author

This was also closed by #8208, only the datetime.time is not resolved, but opened a seperate issue about that (as it now fails silently on master)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO SQL to_sql, read_sql, read_sql_query
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants