Update Row cell Mysql Database


I'm new to retool and I tried searching in the forum and documentation but I still can't get my update cell to work.

I'm building a simple CRUD app that will read a mysql database. I got the delete and add features to work, but I'm confused on how to set up the update. I set the action type to 'update an existing record. Then the filter to {{table1.selectedRow.id}} to get the id of the row I'm trying trying to udpate. Then change set to {{table1.changesetArray}} to get the last change. But my table doesn't get updated. Could anyone please let me know what I'm doing wrong? I know it's prob a silly mistake. I'd appreciate any help.

Hello @tdadmin,

Welcome to the forum!

There's a couple of things that could be going wrong here. First, make sure that the "Primary Key" field in your table component's settings matches the primary key column in your database table. The primary key is the unique identifier for each row in your table, and Retool uses it to determine which row to update.

Second, check the syntax of your filter expression. It should look something like this:

{{table1.selectedRow.id}} = {{table1.changesetArray[0].id}}

This expression checks if the ID of the selected row in the table component matches the ID of the first change in the changeset array. If they match, then the update will be applied to the correct row.

Finally, make sure that you have set the "Update Query" field in your action to the SQL query that you want to use to update the database. The query should look something like this:

UPDATE table_name SET column1 = ?, column2 = ? WHERE id = ?

where table_name is the name of your database table, column1 and column2 are the columns that you want to update, and id is the primary key column.

Hope this helps!



HI Patrick, Thank you for your response. I actually got it to work by using 'update bulk via a PK'. When I click on the tables cells and save the changes it saves to my db. I was reading your response and it seems that you were suggesting a different approach. Do you think my solution is not the optimal one? I'm new to retool and was just using what was available to me. I'd appreciate any insights. Thanks

Hi @tdadmin, welcome to the forum! :wave:
Your solution is perfect! :100: