INSERT / UPDATE / DELETE with Write-Back
INSERT/UPDATE/DELETE on blocks write the change back to the document’s source Markdown file (re-parsed in place, same DocumentId), pass --write-back to allow it; without the flag the statement is rejected:
mq-db sql "UPDATE blocks SET content = 'New Title' WHERE block_type = 'heading' AND content = 'Old Title'" \
--db store.mq-db --write-back
mq-db sql "DELETE FROM blocks WHERE content = 'Outdated paragraph'" \
--db store.mq-db --write-back
# after_pre anchors the new block right after an existing block's `pre`;
# omit it to append at the end of the document.
mq-db sql "INSERT INTO blocks (document_id, block_type, content, depth, after_pre) VALUES (0, 'heading', 'New Section', 2, 4)" \
--db store.mq-db --write-back
mq-db sql "INSERT INTO blocks (document_id, block_type, content) VALUES (0, 'paragraph', 'Appended at the end')" \
--db store.mq-db --write-back
Limitations in this version
UPDATE ... SET contentandINSERT INTO blocksonly supportheading/paragraphblocks (not tables, code, lists, …)INSERT INTO blocksrequires an explicit column list drawn fromdocument_id,block_type,content,depth(required forheading, 1-6),after_pre(optional);INSERT ... SELECTis not supported, onlyVALUES- Only documents indexed with spans (the default; not
--no-spans) and from a real file (not added via the library’sadd_str) are eligible - Not available over
serve’s HTTP endpoint or frommq-mcp: CLI (sql/replwith--write-back) and the library (DocumentStore::execute_sql_mut) only