Hi I have a question. I want to make some fields editable in my table and once they are edited i wanted that data to be updated in my table. However the table doesn't have a primary key so I cant do "Bulk update via a primary key". Whats another option to update the edited values from the retool table to my table in my db?
Hey @Mahaveer_Ukrani , Welcome to the forum!
If your table doesn't have a primary key but you still want to update edited rows in Retool, there's a workaround you can use.
Even without a defined primary key, you probably have a combination of fields that can uniquely identify each row — for example, a mix of email
and signup_date
, or name
and phone_number
.
Use that unique combination to target and update specific rows effectively.
Hi @Mahaveer_Ukrani,
One feasible solution is transforming fetched data from DB into Retool JS Variable with artificial ID.
-
Create Retool JS variable
-
Generate artificial ID with UUID package and transform it. Save it to created JS variable in
onSuccess
event handler.
-
You can now use the artificial ID as the primary key for each row. To insert or update new records in the Retool table component, utilize the
saveAs
event handler with thechangesetArray
andnewRows
attributes of the table component. Refer to this link for implementation details: Table Save Action - Set Table Value In A Variable - #2 by mitchmess -
For bulk updates, you could use the JS variable while ignoring the artificial column.
Both of the above responses are great recommendations, @Mahaveer_Ukrani, and hopefully they've helped to unblock you.
If not, I wanted to ask a clarifying question. Does the table in your database not have a primary key, either?