Search code examples
pandasexasolutionexasol

pandas to_sql with Exasol


When I use to_sql to upload dataframe to exasol and specify if_exists='replace', the default string data type is 'text', which is not supported by Exasol. I think Varchar is the right type. How could I make to_sql to create table with Varchar rather than Text?


Solution

  • I know it's not 100% what you are asking for but I would suggest to use the pyexasol package for communication between Pandas and Exasol. Deleting and following uploading then works like

    import pyexasol
    import _config as config
    
    # Connect with compression enabled
     C = pyexasol.connect(dsn=config.dsn, user=config.user, 
     password=config.password, schema=config.schema,
                     compression=True)
    
    C.execute('TRUNCATE TABLE users_copy')
    
    
    # Import from pandas DataFrame into Exasol table
    C.import_from_pandas(pd, 'users_copy')
    
    stmt = C.last_statement()
    print(f'IMPORTED {stmt.rowcount()} rows in 
    {stmt.execution_time}s')
    C.close()
    

    Problems with varchar do not appear.