ENH/SQL: provide single value to 'dtype' argument in to_sql as dtype for all columns · Issue #11886 · pandas-dev/pandas (original) (raw)

Idea from http://stackoverflow.com/questions/34383000/pandas-to-sql-all-columns-as-nvarchar

You can specify the sql type using the dtype argument in to_sql. Now, this argument has to be a dict (mapping of column name -> type).
Letting to_sql recognize a single value as the sql type for all columns is not that difficult to add.

So instead of this:

df.to_sql(...., dtype={col_name: sqlalchemy.types.NVARCHAR for col_name in df})

you can do this:

df.to_sql(...., dtype=sqlalchemy.types.NVARCHAR)