Skip to content

Add support for schema parameter when calling io.sql.get_schema #28486

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
bbibentyo opened this issue Sep 17, 2019 · 2 comments · Fixed by #38146
Closed

Add support for schema parameter when calling io.sql.get_schema #28486

bbibentyo opened this issue Sep 17, 2019 · 2 comments · Fixed by #38146
Labels
Enhancement IO SQL to_sql, read_sql, read_sql_query
Milestone

Comments

@bbibentyo
Copy link

bbibentyo commented Sep 17, 2019

Currently, there is no way to specify the schema when calling pandas.io.sql.get_schema, the schema is a helpful parameter when working with certain databases such as MSSQL.

import pandas.io.sql

# current state
table_name = 'my_new_table'
sql_create_statement = pandas.io.sql.get_schema(df, table_name, con)
# create statement looks like
"""
CREATE TABLE [my_new_table] (
    [column1] VARCHAR(max) NULL,
    ....
)
"""

this adds an extra step to have to parse the file in order to add the schema, otherwise when I execute the script later, the table is created in user default schema (dbo in most cases). This issue can be easily addressed by adding schema parameter to _create_sql_schema since SQLTable already supports schema

import pandas.io.sql

# future state
table_name = 'my_new_table'
schema = 'pypi'
sql_create_statement = pandas.io.sql.get_schema(df, table_name, schema=schema)

# create statement will look like this for MSSQL if con parameter is passed
"""
CREATE TABLE pypi.[my_new_table] (
    [Column1],
    ....
)
"""
@TomAugspurger
Copy link
Contributor

So this is just a matter of passing the argument through, then things should work? That sounds reasonable to me.

@TomAugspurger TomAugspurger added the IO SQL to_sql, read_sql, read_sql_query label Sep 19, 2019
@TomAugspurger TomAugspurger added this to the Contributions Welcome milestone Sep 19, 2019
@bbibentyo
Copy link
Author

Yes, it's a matter of passing the argument through. Although I am not sure if testing its impact will be as straight forward. I will submit a PR

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
4 participants