Using MERGE to update matched items from a SELECT

n1ql

#1

I see in the documentation that MERGE is supported.

Maybe I’m missing something in the docs, but can I execute a merge against a SELECT?

For example, if I’m using the travel-sample, if I try something like this:

merge into `travel-sample` 
using (select * from `travel-sample` where name='Texas Wings') as d on key d.name
where matched then update set d.iata='Bush'

I get a syntax error:

[
  {
    "code": 3000,
    "msg": "syntax error - at where",
    "query_from_user": "merge into `travel-sample` \nusing (select * from `travel-sample` where name='Texas Wings') as d on key d.name\nwhere matched then update set d.iata='Bush'"
  }
]

Can I accomplish this, and if so, what is the correct syntax.


N1QL update query
MERGE with UPDATE not working as expected?
#2

There is typo. when matched. Also you may want to update merge document not source document.

merge into travel-sample p
using (select * from travel-sample where name=‘Texas Wings’) as d on key d.name
when matched then update set p.iata=‘Bush’


#3

Also you may want to update target document not source document.

merge into travel-sample p
using (select * from travel-sample where name=‘Texas Wings’) as d on key d.name
when matched then update set p.iata=‘Bush’