Skip to main content

How to update rows in a table?

The records in a table can be updated with a PATCH request.

Update


curl --request PATCH \
--url http://localhost:8080/v1/rdbms/pgdb/film \
--header 'Content-Type: application/json' \
--header 'User-Agent: insomnia/9.2.0' \
--data '{

"original_language_id" : 1

}'


HTTP Response

{
"rows": 4
}

The request above updates all the rows in the table and sets the column original_language_id to the value 1.

danger

Update without filter can change all rows.

Update with Filter

It is easy to add filter to update only selected rows as shown in the request below.


curl --request PATCH \
--url 'http://localhost:8080/v1/rdbms/pgdb/film?filter=film_id==1' \
--header 'Content-Type: application/json' \
--header 'User-Agent: insomnia/9.2.0' \
--data '{

"rental_rate" : 1.99,
"length" : 92

}'

HTTP Response

{
"rows": 1
}

The filter condition applies to the primary key film_id of the film table. Hence, only a single record is updated by the update request with filter.