DELETE
Delete rows. The rows stay readable for older transactions, and their keys stay taken until PURGE.
In this article
Deletes the rows that match a condition.
Syntax
DELETE FROM <table> [USING <table> [AS <alias>]] [WHERE <condition>] [RETURNING <item> [, ...]]
WHERE takes the same conditions as SELECT, subqueries included. Without WHERE, every row is deleted.
Examples
DELETE FROM purchases WHERE id = 3;
DELETED 1
DELETE FROM purchases WHERE account_id IN (SELECT id FROM accounts WHERE balance < 600);
USING names one more table that the WHERE can read. A row is deleted when some row of that table matches:
DELETE FROM purchases USING accounts AS a
WHERE a.id = purchases.account_id AND a.owner = 'carol';
RETURNING lists the deleted rows before the reply:
kdbs> DELETE FROM purchases WHERE id = 3 RETURNING id, note
id,note
3,NULL
DELETED 1
How it works
-
A delete marks the row as deleted by your transaction. The row’s bytes stay in place, so a transaction that started earlier still sees it.
-
The deleted row’s primary key stays taken. Inserting a row with the same key is refused until PURGE frees it:
kdbs> INSERT INTO purchases VALUES (3, 2, 3, 1, '2026-10-03', 'reordered'); ^ ERR duplicate tuple key 3: a row with this key was deleted; PURGE frees its key (page 138 slot 2) (byte 30) -
Deleting a parent row that a live child row still references is refused with
FK_VIOLATION:kdbs> DELETE FROM items WHERE id = 1; ERR FK_VIOLATION retryable=0 row id=1 is still referenced by 'purchases.item_id' -
Deletes are never refused by an assertion: assertions are upper bounds, and a delete only lowers a group’s count or sum. The group’s running total is updated.
-
A Transition with
ON DELETE FROMrefuses to delete a row whose state is not listed there. -
A
WHEREliteral of the wrong type for its column is refused when the statement is compiled, so nothing is deleted. It does not answerDELETED 0:kdbs> DELETE FROM purchases WHERE qty = '1'; ^ ERR column 'qty' literal at byte 34: expects an integer literal - unquoted, with no fractionSee SELECT.
-
Indexes and Cabins are not changed by a delete. Every read checks their entries against the row, so a deleted row is never returned.
-
Reply:
DELETED <n>.