Skip to content
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

ENH/SQL: provide single value to 'dtype' argument in to_sql as dtype for all columns #11886

Closed
jorisvandenbossche opened this issue Dec 22, 2015 · 3 comments
Labels
Enhancement IO SQL to_sql, read_sql, read_sql_query
Milestone

Comments

@jorisvandenbossche
Copy link
Member

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)
@jorisvandenbossche jorisvandenbossche added Enhancement IO SQL to_sql, read_sql, read_sql_query labels Dec 22, 2015
@jorisvandenbossche jorisvandenbossche added this to the Next Major Release milestone Dec 22, 2015
@RahulHP
Copy link
Contributor

RahulHP commented Jan 15, 2016

Will it be alright if I:

  1. First check if the dtype passed in is an instance of dict.
  2. If Not, create a dictionary the same was as above ie. {col_name: sqlalchemy.types.NVARCHAR for col_name in df}
  3. Pass this new dictionary onwards.

RahulHP added a commit to RahulHP/pandas that referenced this issue May 27, 2016
RahulHP added a commit to RahulHP/pandas that referenced this issue May 27, 2016
RahulHP added a commit to RahulHP/pandas that referenced this issue May 28, 2016
ENH: support decimal option in PythonParser pandas-dev#12933

closes pandas-dev#12933

Author: Camilo Cota <[email protected]>

Closes pandas-dev#13189 from camilocot/12933 and squashes the following commits:

465272e [Camilo Cota] Benchmark decimal option in read_csv for c engine
9f42d0c [Camilo Cota] double backticks around decimal and engine='python'
dc8ca62 [Camilo Cota] fix test_empty_decimal_marker comment
49613fe [Camilo Cota] Assert read_csv error message in test_empty_decimal_marker
d821052 [Camilo Cota] fix test_empty_decimal_marker comment
f71509d [Camilo Cota] Include descritive what's new line
803356e [Camilo Cota] set nonnum regex in init method
1472d80 [Camilo Cota] Include the issue number in what's new
b560fda [Camilo Cota] Fix what's new
dc7acd1 [Camilo Cota] ENH: support decimal option in PythonParser pandas-dev#12933

ENH: Allow to_sql to recognize single sql type pandas-dev#11886

PEP pandas-dev#3
@jorisvandenbossche jorisvandenbossche modified the milestones: 0.19.0, Next Major Release Jul 23, 2016
@oguzhanogreden
Copy link
Contributor

It seems that this is not documented here: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_sql.html

@jorisvandenbossche
Copy link
Member Author

@oguzhanogreden would you like to do a PR to add it?

TomAugspurger pushed a commit that referenced this issue Aug 30, 2019
MarcoGorelli pushed a commit to MarcoGorelli/pandas that referenced this issue Sep 3, 2019
proost pushed a commit to proost/pandas that referenced this issue Dec 19, 2019
proost pushed a commit to proost/pandas that referenced this issue Dec 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement IO SQL to_sql, read_sql, read_sql_query
Projects
None yet
Development

No branches or pull requests

3 participants