G

UPDATE & DELETE

Standard SQL UPDATE and DELETE work as expected. Both operations write to the WAL and are crash-safe. MVCC ensures concurrent readers see a consistent snapshot.

UPDATE Syntax

SQL
UPDATE table_name
SET col1 = val1 [, col2 = val2, ...]
[WHERE condition];

Returns the number of rows updated.

SQL
-- Update a single row
UPDATE users SET age = 31 WHERE id = 1;

-- Update multiple columns
UPDATE users
SET name = 'Alice Smith', email = 'alice.smith@example.com'
WHERE id = 1;

-- Update all rows matching a condition
UPDATE products SET in_stock = false WHERE price > 1000;

Note

Updating an embedding column re-computes the embedding automatically. The new text value is sent to the sidecar and the HNSW index is updated.

DELETE Syntax

SQL
DELETE FROM table_name [WHERE condition];

Returns the number of rows deleted.

SQL
-- Delete a single row
DELETE FROM users WHERE id = 1;

-- Delete rows matching a condition
DELETE FROM logs WHERE created_at < 1700000000;

-- Delete all rows (table structure remains)
DELETE FROM temp_data;

Warning

DELETE FROM table_name without a WHERE clause deletes all rows. The table structure is preserved. Use DROP TABLE to remove the table entirely.

DROP TABLE

SQL
DROP TABLE table_name;
DROP TABLE IF EXISTS table_name;

Removes the table and all its data, including the HNSW index and any associated version tags. This operation is irreversible.

Examples

Update embedding column

SQL
CREATE TABLE docs (
    id   INT PRIMARY KEY,
    body TEXT EMBEDDING MODEL 'sentence-transformers/all-MiniLM-L6-v2' DIM 384
);

INSERT INTO docs (id, body) VALUES (1, 'original text');

-- Update text — embedding re-computed automatically
UPDATE docs SET body = 'updated text with new content' WHERE id = 1;

Python client UPDATE/DELETE

Python
import galaxdb

db = galaxdb.Database("./data")

# UPDATE returns row count (int)
count = db.execute("UPDATE users SET age = 31 WHERE id = 1")
print(count)  # 1

# DELETE returns row count (int)
count = db.execute("DELETE FROM users WHERE id = 1")
print(count)  # 1

# DROP TABLE returns status string
result = db.execute("DROP TABLE IF EXISTS temp_data")
print(result)  # "OK"

Conditional delete with subquery

SQL
-- Delete inactive users (standard SQL)
DELETE FROM users
WHERE id IN (
    SELECT user_id FROM sessions
    WHERE last_active < 1700000000
);