Delete data
Perform delete operations on MySQL databases via HTTP RESTful API. For details about specific interfaces, refer to HTTP API/MySQL Database.
Basic Syntax
DELETE https://your-envId.api.tcloudbasegateway.com/v1/rdb/rest/:table
Authorization: Bearer <access_token>
💡 Tip: For access_token, refer to Obtain AccessToken
Basic Deletion
# Delete a Single Data Record
curl -X DELETE 'https://{{host}}/v1/rdb/rest/film?id=eq.1' \
-H 'Authorization: Bearer <access_token>'
💡 Note: By default, delete operations do not return data, only status codes and the number of affected rows.
Response
content-range: */1indicates the number of affected rows, meaning one data record has been deleted.preference-applied: return=minimalindicates that the delete operation adopted thereturn=minimalreturn policy (the default behavior for delete operations, which does not generate a response body).
Response Example
HTTP/1.1 204 No Content
Header:
content-length: 0
content-range: */1
preference-applied: return=minimal
Body: (Empty)
Deleting and Returning Data
# Deleting Data and Returning the Deleted Records
curl -X DELETE 'https://{{host}}/v1/rdb/rest/film?select=*&id=eq.2' \
-H 'Authorization: Bearer <access_token>' \
-H 'Prefer: return=representation'
Request
- Specify the Header
Prefer: return=representationin the request to indicate that, by default, all field data before deletion will be returned when performing the delete operation.
💡 Note: Returning data before deletion essentially involves a query + delete operation, which results in two database requests. Both requests are within the same transaction, thus avoiding dirty reads. However, if the query fails, the deletion will also be rolled back.
Response Example
HTTP/1.1 200 OK
Header:
content-length: 266
content-range: */1
preference-applied: return=representation
Body:
[
{
"_openid": "1977683311217119233",
"director": "Frank Darabont",
"duration": 142,
"id": 2,
"release_year": 1994,
"title": "The Shawshank Redemption"
}
]
Complex Conditional Deletion
# Using Complex Conditions to Delete Data
curl -X DELETE 'https://{{host}}/v1/rdb/rest/film?id=in.(7,8,9)&duration.gte.150&limit=2&order=id.desc' \
-H 'Authorization: Bearer <access_token>' \
-H 'Prefer: return=representation'
Request
id=in.(7,8,9): Delete records where the id is among 7, 8, or 9.duration.gte.150: and the duration is greater than or equal to 150 minuteslimit=2: Delete a maximum of 2 records.order=id.desc: Delete after sorting by id in descending order.
Response Example
HTTP/1.1 200 OK
Header:
content-length: 156
content-range: */2
preference-applied: return=representation
Body:
[
{
"id": 9,
"title": "The Dark Knight",
"director": "Christopher Nolan",
"duration": 152
},
{
"id": 8,
"title": "Pulp Fiction",
"director": "Quentin Tarantino",
"duration": 154
}
]