exasol / pyexasol

Exasol Python driver with low overhead, fast HTTP transport and compression
MIT License
72 stars 39 forks source link

update table function - pandas style #81

Closed johnbisc closed 3 years ago

johnbisc commented 3 years ago

I am trying to update a column in a table in the db from a df, but it seems the df is not read properly. any suggestions ? I can't see any function dealing with it in the docs

this is my function

 def update_table_from_pandas(df, table_name, table_id, col_to_update):    

    stmt =f""" UPDATE {table_name} AS a
    SET a.{col_to_update} = {df.dma_id}
    FROM {table_name}, {df}
    WHERE a.{table_id} = {df.CITY_ID} ;"""

    try:
        C.execute(stmt)
        print('table updated')
    except pyexasol.ExaQueryError as e:
        print(e)

thanks

littleK0i commented 3 years ago

Joining dataframe to Exasol table cannot work like this.

What you can do instead:

  1. Create a table with data structure compatible with dataframe "df".
  2. Run .import_from_pandas() to import dataframe into table.
  3. Run UPDATE joining two Exasol tables.