Hi Ben,

> Unfortunately, the insert above just returns an empty set.  I *think* it puts 
> it into some PUL list, not unlike a set of transactions to be applied.  These 
> modifications seem to be invisible to subsequent queries, even in the same 
> session (unlike a SQL database wherein the same session would see the 
> modifications).

Well summarized; this is the way how the XQuery Update Facility works.
As you have created the updated node inside the updating query, and as
updating queries return no results, you won’t have any insight into
the changes.

There are basically two solutions (depending on what you want to do):

1. In SQL, you usually update existing resources. If you want to do
the same in XQuery, you need to address the resource in your quer,
e.g. via fn:doc or db:open:

  insert node element german { 'Friede' } into doc('world.xml')/peace

2. If you want to create new nodes in your query and update and return
those, you can use the “non-updating” expression:

  <peace/> update {
    insert node element german { 'Friede' } into .
  }

> Separately, if I do haver an insert or some other modification, what's the 
> syntax if I wanted to add a for, let order by or other FLOWR keyword?

XQuery is “fully composable”, which means that FLWOR expressions can
be used nearly anywhere. Just an example:

  let $node := <peace/>
  return $node update {
    for $new in (<german>Friede</german>, <french>paix</french>)
    order by name($new)
    return insert node $new into .
  }

Hope this helps
Christian

Reply via email to