Hi Francis,
It's not clear to me what clause of the XQuery Update specification you link disallows deleting a document node. Is it this one?
"If any node in $tlist has no parent, it is removed from $tlist (and is thus ignored in the following step)."
Exactly. It's true that we could start reflecting on the consequences of an additional super node.. But this would most likely introduce numerous other side effects to the existing query and storage architecture.
However, I see some clear advantage if the nodes to be deleted, replaced, etc, could be directly specified. We could think about extending/rewriting the existing db functions (provided that we maintain a consistent solution, and that we manage to avoid new incompatibilities with previous versions of the db module).
I think the github issue you link to rather underestimates how broken this is. This is really a bug and not a nice-to-have.
The "nice2have" tag might have been irritating. I claim, however, that it’s not a bug that multiple documents with the same name can be added to a database. The opposite is true: we have quite a number of users who appreciate the fact that the addition of database resources is lightning fast in BaseX. It’s rather the inconsistent behavior of accompanying functions that causes the problems. Beside that, it will be difficult to keep up the same performance if we start indexing all resource paths.
I also don't understand why that db:replace() expression doesn't work. Reminder:
xquery db:replace('test','test.xml', <root/>)
Stopped at line 1, column 60: [BXDB0006] Database path '%' must point to a single document.
..and I was surprised about the error message ;) I have updated the error feedback, and the behavior of db:replace(). Now, all documents will be deleted that match the specified path, and a single document will be added. Feel free to check out the latest stable snapshot [1].
Christian