Skip to main content

import TabItem from "@theme/TabItem"; import Tabs from "@theme/Tabs";

Data Deletion

The DELETE statement is used to delete data from a table. If no WHERE condition is added to the DELETE statement, it will delete all the data in the table. If an ORDER BY condition exists, the deletion will be done in the specified order. LIMIT can be used to limit the number of data to be deleted.

warning

Using DELETE statements without WHERE and LIMIT clauses can be very dangerous.

Using SDK

Both Python and JavaScript versions of the SDK provide the delete() method for deleting data. Using delete() method requires a WHERE condition to be specified, and the default LIMIT is set to 50. For example, if we want to delete data from a book table where the id is equal to 1, we can execute the following example:

SQL Example

DELETE FROM 'bookshop.book' WHERE id = 1;

Builtin Method

<Tabs defaultValue="Python" values={[ { label: "Python", value: "Python" }, { label: "JavaScript", value: "JavaScript" }, { label: "Golang", value: "Golang" }, ]}

db = client.db(mk)
db.delete(database_name="bookshop", table_name="book", where={"id=": 1}, order_by="id", asc=False, limit=1)
const db = client.db(mk);
await db.delete("bookshop", "book", {id: 1}, "id", false, 1);
resp, err  := glitterClient.Delete(ctx, "bookshop.book", map[string]interface{}{"id": 1}, "id", true, 1)

Execute SQL

Of course, we can also write our own SQL for deletion and call the corresponding SDK's execution method. <Tabs defaultValue="Python" values={[ { label: "Python", value: "Python" }, { label: "JavaScript", value: "JavaScript" }, { label: "Golang", value: "Golang" }, ]}

sql = "DELETE FROM bookshop.book WHERE id = 1 limit 1"
db = client.db(mk)
db.sql_exec(sql)
const sql = "DELETE FROM bookshop.book WHERE id = 1 limit 1";
const db = client.db(mk);
await db.sqlExec(sql);
sql = "DELETE FROM bookshop.book WHERE id = 1 limit 1"
glitterClient.SQLExec(ctx, sql, nil)