# Merging updates

In the middle of a program, several PULs can be produced against the same snapshot. They are then merged with upd:mergeUpdates (part of the XQuery Update Facility standard), which is extended as follows.

* Several deletes on the same object are replaced with a unique delete on that object, with a list of all selectors (names) to be deleted, where duplicates have been eliminated.
* Several deletes on the same array and selector (position) are replaced with a unique delete on that array and with that selector.
* Several inserts on the same array and selector (position) are equivalent to a unique insert on that array and selector with the content of those original inserts appended in an implementation-dependent order (like XQUF).
* Several inserts on the same object are equivalent to a unique insert where the objects containing the pairs to insert are merged. An error jerr:JNUP0005 is raised if a collision occurs.
* Several replaces on the same object or array and with the same selector raise an error jerr:JNUP0009.
* Several renames on the same object and with the same selector raise an error jerr:JNUP0010.
* If there is a replace and a delete on the same object or array and with the same selector, the replace is omitted in the merged PUL.
* If there is a rename and a delete on the same object or array and with the same selector, the rename is omitted in the merged PUL.

<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.rumbledb.org/the-jsoniq-language/jsoniq-update-facility/merging-updates.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
