Delete Data
Delete data from the PostgreSQL database through the HTTP RESTful API. For specific API details, please refer to HTTP API/PostgreSQL Database.
Basic Syntax
DELETE https://your-envId.api.tcloudbasegateway.com/v1/rdb/rest/:table
Authorization: Bearer <access_token>
💡 Tip: For access_token, please refer to Get AccessToken
Basic Delete
# Delete a single record
curl -X DELETE 'https://{{host}}/v1/rdb/rest/film?id=eq.1' \
-H 'Authorization: Bearer <access_token>'
💡 Note: By default, the delete operation does not return data, only the status code and the number of affected rows
Response
content-range: */1indicates the number of affected rows; here it means 1 record was deletedpreference-applied: return=minimalindicates thereturn=minimalreturn strategy was applied during the delete operation (default behavior for delete operations, i.e., no response body is produced)
Response Example
HTTP/1.1 204 No Content
Header:
content-length: 0
content-range: */1
preference-applied: return=minimal
Body: (Empty)
Delete and Return Data
# Delete data and return 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
- Specifying the Header
Prefer: return=representationin the request means the deleted record data will be returned. Internally, this uses theDELETE ... RETURNINGsyntax to complete the deletion and return results in a single query
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 Delete
# Delete data with complex conditions
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 id is 7, 8, or 9duration=gte.150: And duration is greater than or equal to 150 minuteslimit=2: Delete at most 2 recordsorder=id.desc: Sort by id in descending order before deleting
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
}
]