docs/versioned_docs/version-2.24.0/how-to/bulk-update-multiple-rows-in-table.md
Currently, the data sources in ToolJet have operation for bulk update(GUI mode) but that only works for changes made in the single row. We will soon be adding a new operation for bulk updating the multiple rows but for now we can bulk update multiple rows by creating a Custom JS query.
In this guide, We have assumed that you have successfully connected the data source. For this guide, we will be using the PostgreSQL data source as an example database. Currently, this workaround can be used only for PostgreSQL and MySQL.
SELECT * FROM tooljet // replace tooljet with your table name
{{queries.<queryname>.data}} in the Data fieldconst uniqueIdentifier = "id"
const cols = Object.values(components.table1.changeSet).map((col, index) => {
return {
col: Object.keys(col),
[uniqueIdentifier]: Object.values(components.table1.dataUpdates)[index][uniqueIdentifier],
values: Object.values(col),
};
});
const sql = cols.map((column) => {
const { col, id, values } = column;
const cols = col.map((col, index) => `${col} = '${values[index]}'`);
return `UPDATE users SET ${cols.join(", ")} WHERE id = '${id}';`;
});
return sql
:::info Here the Unique identifier is id, this is the column name that is used to identify the row in the database. Update the Unique identifier if you are using a different column name. Update table1 with the name of the table you are using. :::
<div style={{textAlign: 'center'}}> </div>{{queries.runjs1.data.join(' ')}}
{{queries.users.isLoading || queries.update.isLoading}} // add this in the loading state field of the table