Bulk update without primary key

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?

2 Likes

Hey @Mahaveer_Ukrani , Welcome to the forum! :wave:

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.

4 Likes

Hi @Mahaveer_Ukrani,

One feasible solution is transforming fetched data from DB into Retool JS Variable with artificial ID.

  1. Create Retool JS variable

  2. Generate artificial ID with UUID package and transform it. Save it to created JS variable in onSuccess event handler.

  3. 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 the changesetArray and newRows attributes of the table component. Refer to this link for implementation details: Table Save Action - Set Table Value In A Variable - #2 by mitchmess

  4. 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. :+1:

If not, I wanted to ask a clarifying question. Does the table in your database not have a primary key, either?