Update Rows
You can update a single row or multiple rows in a table in the Catalyst Data Store. The table_service reference used in the below code snippets can either be a table instance or table meta created earlier.
Update a Single Row
This particular method allows you to update a single row by constructing an object with modified values in the required columns.
Refer the unique ROWID and pass the newly constructed object that contains the updated row details to the update_row() method. Please note that it is mandatory to specify the ROWID value here. To know more about the component instancedatastore_service and the table instancetable_service used below, please refer to their respective help sections.
Parameters Used
Parameter Name | Data Type | Definition |
---|---|---|
row_data | Array | A Mandatory parameter. Will hold the details of the row to be updated in key-value pairs. |
copy#Update a single row datastore_service = app.datastore() table_service = datastore_service.table("table_name") row_data = {'name': 'Mathew Jones', 'id': '7211', 'age': '31', 'ROWID': 2136000000011011} row_response = table_service.update_row(row_data) logging.info(row_response)
A sample response is shown below :
copy{ CREATORID: "2136000000006003", MODIFIEDTIME: "2021-08-17 13:02:11:184", CREATEDTIME: "2021-08-16 16:29:10:499", Name: "Mathew Jones", ID : "7211", Age: 31, ROWID: "2136000000011011" }
Update Multiple Rows
To update multiple rows, an array of objects is constructed containing the modified row values, which is passed as an argument to the update_rows() method. The ROWIDs are used in corresponding array objects to refer the specific rows which requires modification. To know more about the component instancedatastore_service and the table instancetable_service used below, please refer to their respective help sections.
The response returned here will be resolved to an array of row objects.
Parameters Used
Parameter Name | Data Type | Definition |
---|---|---|
row_data | Array | A Mandatory parameter. Will hold the details of the rows to be updated in key-value pairs. |
copy#Update multiple rows datastore_service = app.datastore() table_service = datastore_service.table("Employee") row_data = [{'name': 'Mathew Jones', 'id': '7211', 'age': '31', 'ROWID': 2136000000034043}, {'name': 'Rhonda Watson', 'id': '7212', 'age': '28', 'ROWID': 2136000000034045}] row_response = table_service.update_rows(row_data)
A sample response is shown below :
copy[ { CREATORID: "2136000000006003", MODIFIEDTIME: "2021-08-24 13:22:14:718", CREATEDTIME: "2021-08-24 13:12:55:999", Name: "Mathew Jones", ID : "7211", Age: 31, ROWID: "2136000000034043" }, { CREATORID: "2136000000006003", MODIFIEDTIME: "2021-08-24 13:22:14:728", CREATEDTIME: "2021-08-24 13:12:56:001", Name: "Rhonda Watson", ID : "7212", Age: 28, ROWID: "2136000000034045" } ]
Last Updated 2025-03-28 18:24:49 +0530 +0530
Yes
No
Send your feedback to us