Using MERGE to update matched items from a SELECT

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.

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’

1 Like

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’