Skip to content

ENH: support index=True for SQL io.sql.get_schema #9084

Open
@jorisvandenbossche

Description

@jorisvandenbossche

pd.io.sql.get_schema can be used to see the schema 'create table' statement. This function should support including the index (which is actually the default for to_sql)

In [31]: df = pd.DataFrame({'col':[1,2,3]}, index=pd.date_range('2012-01-01', periods=3))

In [33]: print pd.io.sql.get_schema(df, 'test_schema', con=engine_postgres)

CREATE TABLE test_schema (
    col BIGINT
)

In [34]: print pd.io.sql.get_schema(df.reset_index(), 'test_schema', con=engine_postgres)

CREATE TABLE test_schema (
    index TIMESTAMP WITHOUT TIME ZONE, 
    col BIGINT
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions