# Updating database with data table

**URL:** <https://community.plotly.com/t/updating-database-with-data-table/76777>\
**Category:** Dash Python\
**Tags:** question\
**Created:** [July 10, 2023, 9:10pm UTC](https://community.plotly.com/t/updating-database-with-data-table/76777 "2023-07-10T21:10:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![acidkans](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@acidkans](https://community.plotly.com/u/acidkans)\
**Post date:** [July 10, 2023, 9:10pm UTC](https://community.plotly.com/t/updating-database-with-data-table/76777/1 "2023-07-10T21:10:29Z")

</div>

Hi All,  
I’m trying to build simple data table layout in dash so I could edit values of my table in Postgress database.  
My approach is to get active\_cell and whenever it’s changed it triggers for sqalchemy to update that cell in database…  
and… it’s not working… simply after clicking"ENTER" I get not value I just edited but value of new cell I’m getting into after enter clicked…  
I’m a complete new to prog

raming and thought dash is the simplest way to program my database frontend…but it’s not so .  
I looked for any solution in this forum but hadn’t found any…  
any solution will be appreciated…

```auto
@app.callback(
    Output(
        'table-invoicing','data'
    ),
    [Input(
        'table-invoicing','active_cell'
    ),
    Input(
        'table-invoicing', 'data'
    ),
    State(
        'table-invoicing', 'data_previous'
    )]
)

def update_table_invoicing_kellner(active_cell,data,data_previous):
    df = pd.DataFrame(data)
    df.index +=1
    df['acceptance_date'] = pd.to_datetime(df['acceptance_date']).dt.date
    # print(df.info()) set search_path to reporting;
    if active_cell:
        if data is not None and data != data_previous:
            # time.sleep(1)
            cell_data = df.iloc[active_cell['row']][active_cell['column']]
            update_statement = f'set search_path to reporting; Update fakturowanie_kellner SET {active_cell["column_id"]} = \'{cell_data}\' WHERE id = {active_cell["row"]+1};'
            print(update_statement)
            conn.execute(sql_text(update_statement))
            conn.commit()
            # df = pd.read_sql_query(con=conn, sql=sql_text(query))
            # return df.to_dict('records')
    return df.to_dict('records')

```
